use of com.axway.ats.core.filetransfer.model.ftp.SftpFileTransferProgressMonitor in project ats-framework by Axway.
the class SftpClient method doConnect.
private void doConnect(String publicKeyAlias) throws FileTransferException {
// make new SFTP object for every new connection
disconnect();
this.jsch = new JSch();
/* NOTE: Due to logging being global (static), if one thread enables debug mode, all threads will log messages,
* and if another thread disables it, logging will be stopped for all threads,
* until at least one thread enables it again
*/
if (isDebugMode()) {
JSch.setLogger(new SftpListener());
debugProgressMonitor = new SftpFileTransferProgressMonitor();
} else {
debugProgressMonitor = null;
}
try {
if (username != null) {
this.session = jsch.getSession(this.username, this.hostname, this.port);
this.session.setPassword(this.password);
} else {
this.jsch.addIdentity(this.keystoreFile, this.publicKeyAlias, this.keystorePassword.getBytes());
this.session = this.jsch.getSession(this.username, this.hostname, this.port);
}
// skip checking of known hosts and verifying RSA keys
this.session.setConfig("StrictHostKeyChecking", "no");
// make keyboard-interactive last authentication method
this.session.setConfig("PreferredAuthentications", "publickey,password,keyboard-interactive");
this.session.setTimeout(this.timeout);
if (this.ciphers != null && this.ciphers.size() > 0) {
StringBuilder ciphers = new StringBuilder();
for (SshCipher cipher : this.ciphers) {
ciphers.append(cipher.getSshAlgorithmName() + ",");
}
this.session.setConfig("cipher.c2s", ciphers.toString());
this.session.setConfig("cipher.s2c", ciphers.toString());
this.session.setConfig("CheckCiphers", ciphers.toString());
}
if (this.listener != null) {
this.listener.setResponses(new ArrayList<String>());
JSch.setLogger((com.jcraft.jsch.Logger) this.listener);
}
/* SFTP reference implementation does not support transfer mode.
Due to that, JSch does not support it either.
For now setTransferMode() has no effect. It may be left like that,
implemented to throw new FileTransferException( "Not implemented" )
or log warning, that SFTP protocol does not support transfer mode change.
*/
this.session.connect();
this.channel = (ChannelSftp) this.session.openChannel("sftp");
this.channel.connect();
} catch (JSchException e) {
throw new FileTransferException("Unable to connect!", e);
}
}
Aggregations