Ciao a tutti,
ho un problema a lavoro che non riesco a risolvere e ci sto sbattendo la testa ormai da parecchio giorni senza venirne a capo.
Ho un servizio ftp che mi trasferisce dei file da un server ftp (o sftp) sorgente a un server ftp (o sftp) destinazione. Ho configurato un trasferimento tra due server sftp. Utilizzo la libreria j2ssh per la connessione, solo che si connette al primo server sftp ma non al secondo, restituendomi un errore nel login (result=2)...
Qualcuno sa come potrei risolvere questo problema?
Ciao e grazie
il codice col quale effettuo la connessione è il seguente:
codice:
private static SftpClient connectSecure(SshClient ssh, FtpSystem system) throws IOException {
String ftpSystem = system.hostName + ":" + system.port;
PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
try {
ssh.connect(system.hostName, system.port, new IgnoreHostKeyVerification());
int result = 0;
if(system.password!=null){
passwordAuthenticationClient.setUsername(system.userName);
passwordAuthenticationClient.setPassword(system.password);
result = ssh.authenticate(passwordAuthenticationClient);
}
else {
PublicKeyAuthenticationClient pkAuthenticationClient = new PublicKeyAuthenticationClient();
pkAuthenticationClient.setUsername(system.userName);
SshPrivateKeyFile file = SshPrivateKeyFile.parse(new File(privateKeyPath));
pkAuthenticationClient.setKey(file.toPrivateKey(null));
result = ssh.authenticate(pkAuthenticationClient);
}
System.out.println(result);
if(result != AuthenticationProtocolState.COMPLETE){
throw new IOException("Login to " + system.hostName + ":" + system.port + " " + passwordAuthenticationClient.getUsername() + "/" + system.password + " failed");
}
logger.info("connected to " + system.hostName + ", " + result);
} catch (IOException e) {
logger.error("connect to " + ftpSystem, e);
throw e;
} catch(Throwable r) {
logger.error("connect to " + r.getMessage());
}
//Open the SFTP channel
return ssh.openSftpClient();
}