J2ssh ssh客户端经常断开连接

时间:2015-03-25 05:57:35

标签: java networking ssh sftp j2ssh

我使用单线程应用程序连接我的客户端服务器架构。基本上这个应用程序将创建许多连接和作业完成后自动关闭它。我们正在获得例外

'com.sshtools.j2ssh.transport.TransportProtocolException:连接未完成'

我们已启用j2ssh日志来找出问题的根本原因。以下是有关该问题的完整详细信息。

Java版:jdk1.6.0_11

使用的API:J2SSH Core 0.2.9(j2ssh-core-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会话 失败了,解决方案是什么?

1 个答案:

答案 0 :(得分:3)

如果您已发布完整日志,那么应该有更多输出,您是否将日志记录更改为DEBUG级别?

查看代码时,如果在密钥交换期间出现问题时会发生此异常,则您连接的服务器可能不支持旧J2SSH API支持的任何密钥交换算法。

您正在使用的J2SSH版本可能已于2009年发布,但自2007年原作者停止投稿以来,很少或根本没有投入API。许多服务器现在禁用较旧的,安全性较低的密钥交换,并且可能会出现这样的问题。

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

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

相关问题