0

我正在使用Ganymed从 JAVA 运行操作系统命令。在 Linux 中,一切都像魅力一样工作。问题出在 Windows 上。我得到错误:There was a problem while connecting to [IP]:[port]。我尝试通过 localhost/router ip/internet ip 和端口 22/1023 进行连接,并且在 Windows 防火墙和路由器上也打开了端口。

我猜问题是在 Linux 中没有任何东西可以像 ssh 一样监听端口。我对吗?

我需要做什么来解决这个问题?

顺便说一句,我看过JSCHlib 但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);
        }
    }
}
4

1 回答 1

0

您应该在 Windows 上安装 open ssh 以保持 ssh 服务器运行,这将充当入站连接的侦听器接口

于 2014-01-13T03:09:54.850 回答