public ChannelSftp getSftpChannel ( ) throws SftpException { try { ChannelSftp channelSftp = ( ChannelSftp ) this . session . openChannel ( "sftp" ) ; channelSftp . connect ( ) ; return channelSftp ; } catch ( JSchException e ) { throw new SftpException ( 0 , "Cannot open a channel to SFTP server" , e ) ; } }
Create new channel every time a command needs to be executed . This is required to support execution of multiple commands in parallel . All created channels are cleaned up when the session is closed .