2013-08-04 34 views
0

我使用Ganymed來從JAVA運行OS命令。在Linux中,一切都像一個魅力。問題出在Windows上。我收到錯誤:There was a problem while connecting to [IP]:[port]。我試圖通過本地主機/路由器IP /互聯網IP和端口22/1023連接,我已經打開了Windows防火牆和路由器上的端口。Ganymed不會連接到JAVA的窗口

我猜問題是心不是任何聽就像Linux中的SSH端口。我對嗎?

我需要做些什麼來解決這個問題?

順便說一句,我看着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

爲了便於識別,監聽器接口:在這種情況下,「Ganymed」有點像一個Java SSH庫,而不是Eclipse版本「木衛三」? – user573215

+0

是基於Java的SSH-2協議實現。我編輯了問題以包含項目鏈接給那些不知道它的人。 – Nir

回答

0

你應該在Windows上安裝開放ssh來保持SSH服務器上運行,這將充當入站連接