This discussion is archived
1 Reply Latest reply: Nov 30, 2010 12:41 PM by rukbat RSS

Sun Solaris 5.10 - SSH 1.1.3-Not able to connect to server with ssh -Urgent

819973 Newbie
Currently Being Moderated
Hi,
I am not able to coonect to a server using the using the below code.

If i try the same code on the server to connect it self, it is working fine. But when i try to connect from other server it give the below error. And i am using the IBM Jdk while getting this error. Is there some setting to avoid this error.

Error:
INFO: Adding /usr/jdk/instances/jdk1.6.0/jre/lib/ext/sunpkcs11.jar to the extension classpath
ConfigurationLoader
Nov 30, 2010 4:33:12 PM com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory <clinit>
INFO: Loading public key algorithms
Error While SFTP
java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
at java.util.StringTokenizer.nextElement(StringTokenizer.java:390)
at com.sshtools.j2ssh.transport.AbstractKnownHostsKeyVerification.<init>(Unknown Source)
at com.sshtools.j2ssh.transport.ConsoleKnownHostsKeyVerification.<init>(Unknown Source)
at com.sshtools.j2ssh.SshClient.connect(Unknown Source)
at fileTransfer.connectToServer(fileTransfer.java:18)
at fileTransfer.main(fileTransfer.java:56)



Code:
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)
{
System.out.println("Error While SFTP ");
sfc.disconnect();
e.getStackTrace();
return false;
}
return true;
}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points