-1

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()

}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Jay Kishore
  • 19
  • 1
  • 8
  • Please [edit] your question to include the actual error message that you're getting, including the stack trace. – Kenster Jun 05 '17 at 20:25
  • that was some other issue it got solved...this the current scenario – Jay Kishore Jun 05 '17 at 20:37
  • i debugged a little and found out that in the session.openChannel() method it is failing at the following line : if(!isConnected){ throw new JSchException("session is down"); } – Jay Kishore Jun 05 '17 at 20:39
  • So did you debug `session.connect()` to see how it comes it neither connects nor throws an exception? + How do you even pass the `StrictHostKeyChecking=yes`, if you do not specify a host key anywhere? – Martin Prikryl Jun 05 '17 at 20:44
  • i have tried by setting StrictHostKeyChecking=no, i am getting the same exception. – Jay Kishore Jun 06 '17 at 11:31
  • I never recommended you to use `StrictHostKeyChecking=no`! I just wrote that with `=yes` (what is the right way), you need more code. Anyway, you didn't answer my primary question: *Did you debug `session.connect()` to see how it comes it neither connects nor throws an exception?* – Martin Prikryl Jun 07 '17 at 11:59
  • I got the issue...Actually JSch is not an FTP client it's an SSH client (with an included SFTP implementation). And the ftp server which i am connecting with is not a ssh server. That's why jsch is unable to connect with that ftp server. I have used apache commons ftp client and its working fine. – Jay Kishore Jun 16 '17 at 12:36
  • Possible duplicate of [jsch : how to keep the session alive and up](https://stackoverflow.com/questions/16127200/jsch-how-to-keep-the-session-alive-and-up) – Gregor Sep 01 '17 at 14:22

1 Answers1

-1

I got the issue...Actually JSch is not an FTP client it's an SSH client (with an included SFTP implementation). And the ftp server which i am connecting with is not a ssh server. That's why jsch is unable to connect with that ftp server. I have used apache commons ftp client and its working fine

Jay Kishore
  • 19
  • 1
  • 8