我使用follawing代码通过Windows在Linux上执行命令:
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();
但它在第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)
如何解决此类错误?