Reputation: 137
This is the thing, I am trying to connect from java to a FileZilla FTPS Server. I can make the login, but when I try to list the files I get an Exception:
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
at org.apache.commons.net.ftp.FTPSClient._openDataConnection_(FTPSClient.java:619)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:759)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3293)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:482)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
I have tried every possible solution on line, nothing has worked for me, this is the code I´m using (with apache commons-net):
FTPSClient ftps = new FTPSClient();
ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
ftps.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftps.connect("xxx.xx.x.xx",8500);
reply = ftps.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftps.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
if (!ftps.login("user", "*******")) {
ftps.logout();
}
ftps.setBufferSize(1000);
ftps.execPBSZ(0);
ftps.execPROT("P");
ftps.enterLocalPassiveMode();
ftps.changeWorkingDirectory("/");
FTPFile[] files = ftps.listFiles();
ftps.logout();
I will really appreciate your help guys. Thanks in advance.
Upvotes: 3
Views: 2657
Reputation: 137
I found the solution. It was something related with the Session reuse, Apache Commons Net has some kind of bug, It does not allow you to reuse the session, I had to implement the cyberduck library cyberduck source code. I hope this helps someone in the future, thanks for your help.
Upvotes: 1