Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.4k views
in Java FTP by (200 points)
Currently on our Linux server we connect to a remote SFTP server using the following command:
sftp -o IdentityFile=/path/to/file/myFile username@foo.bar.com


I just downloaded the trial version of edtFTPj/PRO to see if we could accomplish the same thing but I'm running into problems. Here's the code I'm using:
SSHFTPClient ftp = new SSHFTPClient();
ftp.setRemoteHost("foo.bar.com");
ftp.setAuthentication("/path/to/file/myFile", "username");
ftp.getValidator().loadKnownHosts("/path/to/known_hosts");
ftp.connect();


I get the following error:
com.enterprisedt.net.j2ssh.authentication.AuthenticationProtocolException: Failed to read messages
        at com.enterprisedt.net.j2ssh.authentication.AuthenticationProtocolClient.A(Unknown Source)
        at com.enterprisedt.net.j2ssh.authentication.AuthenticationProtocolClient.readMessage(Unknown Source)
        at com.enterprisedt.net.j2ssh.authentication.PasswordAuthenticationClient.authenticate(Unknown Source)
        at com.enterprisedt.net.j2ssh.authentication.AuthenticationProtocolClient.authenticate(Unknown Source)
        at com.enterprisedt.net.j2ssh.SshClient.authenticate(Unknown Source)
        at com.enterprisedt.net.ftp.ssh.SCPClient.connectSSH(Unknown Source)
        at com.enterprisedt.net.ftp.ssh.SSHFTPClient.connect(Unknown Source)
        at com.remitpro.zftp.main(zftp.java:67)
Caused by: com.enterprisedt.net.j2ssh.transport.MessageStoreEOFException: The message store has reached EOF
        at com.enterprisedt.net.j2ssh.transport.SshMessageStore.getMessage(Unknown Source)
        at com.enterprisedt.net.j2ssh.transport.SshMessageStore.getMessage(Unknown Source)
        ... 8 more


I'm obviously not setting something up correctly...any advice?

4 Answers

0 votes
by (200 points)
Ok, got it working. Evidently even though the keyFilePassPhrase parameter for the setAuthentication() method is optional, you must still supply one.

I changed:
ftp.setAuthentication("/path/to/file/myFile", "username");

to:
ftp.setAuthentication("/path/to/file/myFile", "username", "");

and can now connect fine.
0 votes
by (51.6k points)
That's great. Thanks for letting us know.

- Hans (EnterpriseDT)
0 votes
by (162k points)
Ok, got it working. Evidently even though the keyFilePassPhrase parameter for the setAuthentication() method is optional, you must still supply one.


The reason is that if you don't supply one, you are using this method

setAuthentication(String userName, String password)

and the keyFile is being used as the username.
0 votes
by (200 points)
Ok, got it working. Evidently even though the keyFilePassPhrase parameter for the setAuthentication() method is optional, you must still supply one.


The reason is that if you don't supply one, you are using this method

setAuthentication(String userName, String password)

and the keyFile is being used as the username.
:oops:

Categories

...