/***********************************************************************/ private void closeSsh() { ssh.disconnect(); ssh = null; } /***********************************************************************/
@Override public void close() throws IOException { ssh.disconnect(); super.close(); }
/** Disconnect * @param ssh */ public static void disConnect(SshClient ssh) { if(ssh.isConnected()){ ssh.disconnect(); } }
/***********************************************************************/ 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; } /***********************************************************************/
sessionChannel.getState().waitForState(ChannelState.CHANNEL_CLOSED); br.close(); ssh.disconnect(); return commandOutput; ssh.disconnect(); return commandOutput;