【发布时间】:2015-11-26 23:31:50
【问题描述】:
就是这样,我正在尝试从 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();
非常感谢你们的帮助。提前致谢。
【问题讨论】:
-
你能给我你的 filezilla 凭据吗?
-
看起来像 networkimg 问题 - 错误的端口号或中间的代理通常是嫌疑人。
-
这可能是可能的,但我可以使用任何 ftp 客户端软件列出、下载和上传文件到同一个 FTPS 服务器,所以我想这不是网络问题:\ ...也许是与证书有关的东西
-
@Jhon Charles 关于证书的问题?可能。您是否在当前的 JRE 中安装了远程服务器的证书?
-
嗯...我认为问题不在于身份验证,因为您正在使用用户和通过验证,而不是使用证书...我想你可以不要使用主动模式而不是被动模式,可以吗?