有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java J2ssh客户端经常断开连接

我使用单线程应用程序连接我的客户机-服务器体系结构。基本上,此应用程序将创建许多连接&;作业完成后自动关闭它。我们得到了一个例外

'com。sshtools。j2ssh。运输TransportProtocolException:连接未完成“

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

Java版本:jdk1。6.0_11

使用的API:J2SSH核心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) 个答案

  1. # 1 楼答案

    如果您发布了完整的日志,那么应该会有更多的输出,您是否将日志设置为调试级别

    从代码来看,当密钥交换过程中出现问题时会出现这种异常,可能您连接的服务器不支持旧的J2SSH API支持的任何密钥交换算法

    您正在使用的J2SSH版本可能已经在2009年发布,但自2007年原作者停止贡献以来,该API几乎没有或根本没有投入任何工作。许多服务器现在禁用了较旧的、不太安全的密钥交换,这很可能是造成问题的原因

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

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