简体   繁体   English

J2ssh ssh客户端频繁断开连接

[英]J2ssh ssh client disconnected frequently

I am using a single thread application to connect my client server Architecture. 我正在使用单线程应用程序连接我的客户端服务器体系结构。 Basically this application will create many connections & close it automatically once the job is completed. 基本上,此应用程序将创建许多连接并在作业完成后自动将其关闭。 We are getting an exception 我们正在例外

'com.sshtools.j2ssh.transport.TransportProtocolException: The connection did not complete' 'com.sshtools.j2ssh.transport.TransportProtocolException:连接未完成'

We have enabled j2ssh logs to figure out the root cause of the issue. 我们已启用j2ssh日志以找出问题的根本原因。 Below are the complete details about the issue. 以下是有关此问题的完整详细信息。

Java Version : jdk1.6.0_11 Java版本:jdk1.6.0_11

API Used : J2SSH Core 0.2.9 (j2ssh-core-0.2.9.jar) 使用的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)

........ and the following code ........以及以下代码

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();
        }
    }

Is there any way to overcome this error? 有什么办法可以克服这个错误? As this kind of error will cause one sftp session of the application to be failed, what is the solution for this? 由于这种错误将导致应用程序的一个sftp会话失败,该如何解决?

If you have posted the complete log there should be more output, did you turn the logging up to DEBUG level? 如果发布了完整的日志,应该会有更多输出,是否将日志设置为DEBUG级别?

Looking at the code this exception occurs when something went wrong during key exchange, maybe the server you are connecting to does not support any of the key exchange algorithms that the old J2SSH API supports. 查看代码,当密钥交换期间出现问题时会发生此异常,也许您连接的服务器不支持旧J2SSH API支持的任何密钥交换算法。

The version of J2SSH you are using may have been released in 2009 but little or no work has been put into the API since 2007 when the original author stopped contributing. 您使用的J2SSH版本可能于2009年发布,但自2007年原始作者停止贡献以来,该API几乎没有投入任何工作。 Many servers now disable older, less secure key exchanges and its likely its something like this that is causing the problem. 现在,许多服务器都禁用了较旧的,安全性较低的密钥交换,这很可能导致了问题。

If you want to continue using a J2SSH like API rather than JSch you can use the open source version of J2SSH Maverick which is from the same author as J2SSH (that's me btw). 如果您想继续使用类似API的J2SSH而不是JSch,则可以使用J2SSH Maverick的开源版本,该版本与J2SSH是同一作者(即我)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM