4

I use follawing code to execute commands on Linux via Windows:

  JSch jsch=new JSch();  
    Session session=jsch.getSession(user, host, port);
    session.setConfig(props);
    session.setPassword(pwd);
    session.connect();
    ChannelShell channel = (ChannelShell)session.openChannel("shell");
    boolean ch = channel.isConnected();
    channel.sendSignal("ls");
    channel.connect();
    boolean ch1 = channel.isConnected();

But it fails on line channel.connect();:

com.jcraft.jsch.JSchException: session is down
at com.jcraft.jsch.Channel.connect(Channel.java:172)
at com.jcraft.jsch.Channel.connect(Channel.java:132)

How fix such error?

khris
  • 4,809
  • 21
  • 64
  • 94
  • possible duplicate of [jsch : how to keep the session alive and up](http://stackoverflow.com/questions/16127200/jsch-how-to-keep-the-session-alive-and-up) – bummi Jul 22 '15 at 12:30
  • This does not appear to be a duplicate because it's a new session. – pohart Apr 02 '19 at 14:13

1 Answers1

1

Try to use some polling where you can check active status of session. for reference you can check this link

Community
  • 1
  • 1