java + sftp
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?