Karthick88it
Karthick88it

Reputation: 623

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'

We have enabled j2ssh logs to figure out the root cause of the issue. Below are the complete details about the issue.

Java Version : jdk1.6.0_11

API Used : 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?

Upvotes: 0

Views: 2787

Answers (1)

LeeDavidPainter
LeeDavidPainter

Reputation: 126

If you have posted the complete log there should be more output, did you turn the logging up to DEBUG level?

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.

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. 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).

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

Upvotes: 3

Related Questions