2015-03-25 169 views
0

我使用的是单线程应用程序连接我的客户服务器结构。基本上这个应用程序将创建许多连接&一旦工作完成后自动关闭它。我们正在一个异常J2SSH ssh客户端断开频繁

“com.sshtools.j2ssh.transport.TransportProtocolException:连接没有完成”

我们已经启用J2SSH日志以找出问题的根本原因。以下是有关该问题的完整详情。

Java版本:jdk1.6.0_11

API使用:J2SSH核心0.2.9(J2SSH核心-0.2.9.jar)

com.sshtools.j2ssh.transport.TransportProtocolException: The connection did not complete 
    at com.sshtools.j2ssh.transport.TransportProtocolClient.onStartTransportProtocol(Unknown Source) 
    at com.sshtools.j2ssh.transport.TransportProtocolCommon.startTransportProtocol(Unknown Source) 
    at com.sshtools.j2ssh.SshClient.connect(Unknown Source) 
    at com.sshtools.j2ssh.SshClient.connect(Unknown Source) 
    at com.sshtools.j2ssh.SshClient.connect(Unknown Source) 
    at info.itserv.globalinterface.gui.SFTP.openSSH(SFTP.java:95) 
    at info.itserv.globalinterface.gui.SFTP.connectionSFTP(SFTP.java:228) 

........和以下代码

public void openSSH(String hostname, int authCode) { 
     try { 

      sshClient.connect(hostname, 
           new IgnoreHostKeyVerification()); 
      sshClient.getConnectionProperties().setPort(this.port); 
      //Authenticate 
      GENERAL.println("Processing logging..."); 
      switch (authCode) { 
      case 0: 
       this.login(this.username, this.password); 
       System.out.println("Password authentication"); 
       break; 
      case 1: 

       //String keyFilename = "D:\\Cygwin\\home\\gtantot\\id_dsa"; 
       this.loginCertificat(this.username, this.keyFilename, 
            this.passphrase); 
       System.out.println("Password authentication"); 
       break; 
      default: 
       System.out.println("ECHEC SSH connection"); 
       break; 
      } 
      this.sftp = sshClient.openSftpClient(); 

     } catch (TransportProtocolException e) { 
      System.out.println("Transport: "+e.getMessage().toString()); 

      e.printStackTrace(); 

     } 
     catch (IOException e1) { 
      System.out.println("Error openSSH: "+e1.getMessage()); 
      e1.printStackTrace(); 

     } } 

    public void closeSSH() { 
     if (sshClient != null) { 
      sshClient.disconnect(); 
     } 
    } 

有什么办法可以解决这个错误吗? 由于这种错误会导致应用程序 的一个SFTP会议失败了,究竟是什么解决办法吗?

+0

Java SE 6的更新11发行日期2008-12-03 ==,J2SSH发布日期2009年5月19日 - 时间新的东西? – 2015-03-25 06:04:59

+0

尝试使用jsch,它奇妙地工作 – 2015-03-25 06:05:55

+0

感谢您的建议Wombat ..)我也试过更新到Java 7。但同样的问题发生。如果没有办法,我只需要试试jsch .. – 2015-03-25 06:13:32

回答

2

如果您已经发布了完整的日志应该有更多的输出,并打开记录多达DEBUG级别?

看着东西时,密钥交换过程中出了问题,就会出现此异常的代码,也许你正在连接的服务器不支持任何旧J2SSH API支持的密钥交换算法。

您正在使用的J2SSH的版本可能已在2009年发布,但是当原作者停止贡献很少或根本没有工作已自2007年以来投入的API。现在许多服务器禁用较旧的,不太安全的密钥交换,并且可能会导致此问题。

如果你想继续使用类似API的J2SSH而不是JSch,你可以使用与J2SSH相同的作者的J2SSH Maverick的开源版本(这是我的顺便说一句)。

https://github.com/sshtools/j2ssh-maverick