java + sftp

B

Bumsys

I execute the program:

public class SshExample {

/**
* @param args
*/

public static void main(String[] args) {
// TODO Auto-generated method stub
SshClient ssh = new SshClient();

try {
String hostname = "localhost";
System.out.print("Host to connect: " + hostname);
ssh.connect(hostname);
// ssh.connect("localhost", new
ConsoleKnownHostsKeyVerification());

PasswordAuthenticationClient pwd = new
PasswordAuthenticationClient();

String username = "anabolik";
System.out.print("Username: " + username);
pwd.setUsername(username);

String password = "111";
System.out.print("Password: " + password);
pwd.setPassword(password);

int result = ssh.authenticate(pwd);

if(result==AuthenticationProtocolState.FAILED)
System.out.println("The authentication failed");

if(result==AuthenticationProtocolState.PARTIAL)
System.out.println("The authentication succeeded but
another"
+ "authentication is required");

if(result==AuthenticationProtocolState.COMPLETE)
System.out.println("The authentication is complete");




SftpClient sftp = ssh.openSftpClient();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

When the execute the line SftpClient sftp = ssh.openSftpClient(); I
have error:

SEVERE: The Transport Protocol thread failed
java.lang.NegativeArraySizeException
at com.sshtools.j2ssh.io.ByteArrayReader.readString(Unknown Source)
at
com.sshtools.j2ssh.connection.SshMsgChannelOpenFailure.constructMessage(Unknown
Source)
at com.sshtools.j2ssh.transport.SshMessage.fromByteArray(Unknown
Source)
at com.sshtools.j2ssh.transport.SshMessageStore.createMessage(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:619)
java.io.IOException: The message store has reached EOF
at
com.sshtools.j2ssh.connection.ConnectionProtocol.openChannel(Unknown
Source)
at com.sshtools.j2ssh.SshClient.openChannel(Unknown Source)
at com.sshtools.j2ssh.SshClient.openSftpChannel(Unknown Source)
at com.sshtools.j2ssh.SftpClient.<init>(Unknown Source)
at com.sshtools.j2ssh.SshClient.openSftpClient(Unknown Source)
at com.sshtools.j2ssh.SshClient.openSftpClient(Unknown Source)
at research.SshExample.main(SshExample.java:71)

What can do?
 
D

dontlikenicknames

First of all, is the authentication succeeding? What is this block
printing out?

if(result==AuthenticationProtocolState.FAILED)
System.out.println("The authentication failed");

if(result==AuthenticationProtocolState.PARTIAL)
System.out.println("The authentication succeeded but
another"
+ "authentication is required");

if(result==AuthenticationProtocolState.COMPLETE)
System.out.println("The authentication is complete");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top