/***********************************************************************/ public static void sftpUpload(FTPConfig config, File file, String remoteFileName) throws IOException { SshClient ssh = new SshClient(); SftpClient sftp = sshLogin(config, ssh); sftp.mkdirs(remoteFileName.substring(0, remoteFileName.lastIndexOf("/"))); sftp.put(new FileInputStream(file), remoteFileName); sftp.quit(); ssh.disconnect(); } /************************************************************************/
/************************************************************************/ public static File sftpDownload(FTPConfig config, File file, String remoteFileName) throws IOException { SshClient ssh = new SshClient(); SftpClient sftp = sshLogin(config, ssh); sftp.get(remoteFileName, new FileOutputStream(file)); sftp.quit(); ssh.disconnect(); return file; } /***********************************************************************/
@Override public void destroyObject(final PooledObject<WrappedSftpClient> pooledClient) throws Exception { final WrappedSftpClient client = pooledClient.getObject(); if (client != null) { final SftpClient activeSftpClient = client.getActiveSftpClient(); if (this.logger.isLoggable(Level.FINEST)) { this.logger.finest( "Log out user and disconnect ssh session : [" + this.connectionConfiguration.toString() + "]"); } if (activeSftpClient != null && !activeSftpClient.isClosed()) { activeSftpClient.quit(); } if (client.isConnected()) { client.disconnect(); } } }
SftpClient activeSftpClient = client.getActiveSftpClient(); if (activeSftpClient != null && !activeSftpClient.isClosed()) { activeSftpClient.quit();