Getting session and SFTP channel in Java using JSch library
I am using JSch library for SFTP. I need to do several operations on SFTP server like move remote files in other directory, pull files, etc. For all these operations I need Session and from it I get Channel an then cast it to ChannelSftp . This is redundant step. So I thought of abstracting it into a private method. private ChannelSftp getChannelSftp() throws JSchException { java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); JSch jsch = new JSch(); Session session; session = jsch.getSession(VENDOR1_USERID, VENDOR1_SERVER, VENDOR1_PORT); session