我正在使用Ganymed从JAVA运行操作系统命令。在Linux中,一切都像魅力一样。问题出在Windows上。我收到错误:There was a problem while connecting to [IP]:[port]
。我试图通过localhost /路由器ip / internet ip和端口22/1023连接,我也打开了Windows防火墙和路由器上的端口。
我猜测问题是在Linux中没有像ssh那样监听端口的东西。我对吗?
我需要做些什么来解决这个问题?
BTW我看过JSCH
lib,但Ganymed
更简单
这是我的示例代码:
public class Test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String hostname = "192.168.xxx.xxx", username = "xxx", password = "xxx";
int port = 1023;
try {
Connection conn = new Connection(hostname,port);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false) {
throw new IOException("Authentication failed.");
}
Session sess = conn.openSession();
sess.execCommand("ver");
System.out.println("Here is some information about the remote host:");
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) {
String line = br.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
System.out.println("ExitCode: " + sess.getExitStatus());
sess.close();
conn.close();
} catch (IOException e) {
e.printStackTrace(System.err);
System.exit(2);
}
}
}
答案 0 :(得分:0)
你应该在windows上安装open ssh来保持ssh服务器的运行,这将作为入站连接的监听器接口