我使用jsch连接到服务器,它使用Exec和shell通道发送命令,现在我想通过第一个连接连接到另一个服务器,但是当尝试连接第二个会话时应用程序崩溃,不确定如果我正确设置代码
public Session Connect() throws JSchException{
String host1 = "192.168.1.1";
String host2 = "192.168.2.2";
String username = "host";
String password = "pass";
JSch jsch = new JSch();
Session s;
s = jsch.getSession(username, host1, 22);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
s.setConfig(config);
s.setPassword(password);
s.connect();
s.setPortForwardingL(22, host2, 22);
Session secondSession = jsch.getSession(username, host2, 22);
config.put("StrictHostKeyChecking", "no");
secondSession.setConfig(config);
secondSession.setPassword(password);
secondSession.connect();
return secondSession;
}
答案 0 :(得分:1)
在您声明并分配给secondSession
之后,您不是指setConfig
上的setPassword
和secondSession
而不是s
上的secondSession.setConfig(config);
secondSession.setPassword(password);
secondSession.connect();
吗? / p>
TypeStatusDetails