#91 SshClient.connect(IP,Port) failing

None
open
nobody
J2SSH (50)
5
2013-12-13
2013-05-09
Mahesh
No

We are facing SFTP connection issue with the metod SshClient.connect(IP,22) on port 22. This is happening only on few machines, but SFTP through putty will establish connection to the server successfully. We are using a simple stand alone program to connect using sftp protocol.

SSH Version:
bash-3.2$ ssh -V
Sun_SSH_1.1.4, SSH protocols 1.5/2.0, OpenSSL 0x0090704f

Java Version:
1.6.0_30

Jar:
j2ssh-core-0.2.5.jar

Sample Program:

import com.sshtools.j2ssh.SftpClient;
import com.sshtools.j2ssh.SshClient;
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
import com.sshtools.j2ssh.configuration.ConfigurationLoader;
import java.io.PrintStream;

public class fileTransfer
{
public static boolean connectToServer(String serverIp, int serverPort, String userId, String password)
{
SshClient sfc = null;
try {
System.out.println("inside Try of as its SFTP");
ConfigurationLoader.initialize(false);
System.out.println("ConfigurationLoader");

sfc = new SshClient();
sfc.connect(serverIp, serverPort);
System.out.println("sfc.connect");

PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();

pwd.setUsername(userId);

pwd.setPassword(password);

int checkAuth = sfc.authenticate(pwd);
System.out.println("checkAuth " + checkAuth);

if (checkAuth == 4) {
System.out.println("AuthenticationProtocolState.COMPLETE");

SftpClient sftp = sfc.openSftpClient();
sftp.quit();
sfc.disconnect();
}
else
{
throw new Exception("Invalid User Name or Password for user");
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Error While SFTP ");
sfc.disconnect();
e.getStackTrace();
return false;
}
return true;
}

public static void main(String[] args)
{
try
{
System.out.println(connectToServer(args[0], Integer.parseInt(args[1]), args[2], args[3]));
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}

Error:
com.sshtools.j2ssh.transport.TransportProtocolCommon run
SEVERE: The Transport Protocol thread failed
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.sshtools.j2ssh.transport.TransportProtocolInputStream.readBufferedData(Unknown Source)
at com.sshtools.j2ssh.transport.TransportProtocolInputStream.readMessage(Unknown Source)
at com.sshtools.j2ssh.transport.TransportProtocolCommon.processMessages(Unknown Source)
at com.sshtools.j2ssh.transport.TransportProtocolCommon.startBinaryPacketProtocol(Unknown Source)
at com.sshtools.j2ssh.transport.TransportProtocolCommon.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
com.sshtools.j2ssh.transport.MessageStoreEOFException: The message store has reached EOF
at com.sshtools.j2ssh.transport.SshMessageStore.getMessage(Unknown Source)
at com.sshtools.j2ssh.transport.SshMessageStore.getMessage(Unknown Source)
at com.sshtools.j2ssh.transport.SshMessageStore.getMessage(Unknown Source)
at com.sshtools.j2ssh.transport.TransportProtocolClient.requestService(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 fileTransfer.connectToServer(fileTransfer.java:18)
at fileTransfer.main(fileTransfer.java:57)
Error While SFTP
false

Please help us in resolving this issue.

Discussion

  • Sascha Hunold
    Sascha Hunold
    2013-12-13

    Does the error occur with latest stable or SVN version?