When I am trying to get connected with the ftp server for file uploading, I am getting exception com.jcraft.jsch.JSchException: session is down
Code is in groovy:
String SFTPHOST = "########"
int SFTPPORT = 22
String SFTPUSER = "########"
String SFTPPASS = "########"
String SFTPWORKINGDIR = "/QA/"
ChannelSftp sftp = null
Session session = null
try {
JSch jsch = new JSch()
session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT)
session.setPassword(SFTPPASS)
session.setConfig("StrictHostKeyChecking", "no")
session.setConfig("PreferredAuthentications",
"publickey,keyboard-interactive,password")
session.connect()
Channel channel = session.openChannel "sftp"
channel.connect()
sftp = channel as ChannelSftp
sftp.cd SFTPWORKINGDIR
File f = new File("Demo.csv")
sftp.put(new FileInputStream(f), f.getName())
//def fileList = sftp.ls("*")
println fileList.size()
} catch (Exception ex) {
ex.printStackTrace()
}