Java 连接到 FileZilla 服务器
Java connection to FileZilla Server
就是这样,我正在尝试从 java 连接到 FileZilla FTPS 服务器。我可以登录,但是当我尝试列出文件时出现异常:
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)
我已经尝试了所有可能的在线解决方案,但没有任何效果,这是我使用的代码(使用 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();
非常感谢你们的帮助。提前致谢。
我找到了解决方案。这与会话重用有关,Apache Commons Net 有某种错误,它不允许您重用会话,我不得不实现 cyberduck 库 cyberduck source code。我希望这对以后的人有所帮助,感谢您的帮助。
就是这样,我正在尝试从 java 连接到 FileZilla FTPS 服务器。我可以登录,但是当我尝试列出文件时出现异常:
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)
我已经尝试了所有可能的在线解决方案,但没有任何效果,这是我使用的代码(使用 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();
非常感谢你们的帮助。提前致谢。
我找到了解决方案。这与会话重用有关,Apache Commons Net 有某种错误,它不允许您重用会话,我不得不实现 cyberduck 库 cyberduck source code。我希望这对以后的人有所帮助,感谢您的帮助。