java - 使用 Commons Net FTPSClient 连接到 FTP 服务器时出现 "Remote host closed connection during handshake"

标签 java ssl ftp apache-commons-net

我的代码(我在运行时使用-Dhttps.protocols=TLSv1.2 VM 参数):

FTPSClient ftpClient = new FTPSClient("TLS", false);
ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
ftpClient.setAuthValue("TLS");

ftpClient.connect("myhost", 990);
ftpClient.login("mylogin", "mypassword");

堆栈跟踪:

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:992)
// too many traces...
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
... 33 more

从 WinSCP 登录(我可以使用 WinSCP 发送文件):

536 Copying 1 files/directories to remote directory "/" 536 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: Yes; Mask: . 536 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0 536 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml 539 File: 'C:\Users\trescon.jramos\Documents\cliente-dados.sql' [2016-10-06T16:34:29.298Z] [4869] 557 Copying "C:\Users\trescon.jramos\Documents\cliente-dados.sql" to remote directory started. 560 Binary transfer mode selected. 560 Iniciando carregamento de C:\Users\trescon.jramos\Documents\cliente-dados.sql 560 TYPE I 562 200 Type set to I 563 PASV 568 227 Entering Passive Mode (10,28,14,218,250,0) 569 STOR cliente-dados.sql 569 Conectando a 10.28.14.218:64000... 575 150 Opening data channel for file upload to server of "/cliente-dados.sql" 579 Session ID reused 579 Using TLSv1.2, cipher TLSv1/SSLv3: ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA, ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD 580 Conexão SSL estabelecida 586 226 Successfully transferred "/cliente-dados.sql" 586 MFMT 20161006163429 cliente-dados.sql 590 213 modify=20161006163429; /cliente-dados.sql 590 Carregamento bem-sucedido 591 Transfer done: 'C:\Users\trescon.jramos\Documents\cliente-dados.sql' [4869]

最佳答案

您正在连接到端口 990,这是一个隐式 FTPS 端口。然而,您将 false 传递给 FTPSClient constructorisImplicit 参数.

要么传递 true,如果你真的想使用隐式 FTPS:

FTPSClient ftpClient = new FTPSClient("TLS", true);

或者实际上,您应该真正使用显式 FTPS 和默认 FTP 端口 21(因为隐式 FTPS 是非标准的遗留兼容性 hack):

FTPSClient ftpClient = new FTPSClient();
// ...
ftpClient.connect("myhost");

换句话说,使用 FTPS 所需要做的就是使用 FTPSClient ,不需要额外的参数或调用。

关于java - 使用 Commons Net FTPSClient 连接到 FTP 服务器时出现 "Remote host closed connection during handshake",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44119152/

相关文章:

java - 按原始 boolean 类型对 ArrayList 进行排序

ssl - Nginx:基于国家的 SSL 证书

Python - 在 FTP 中按 block 上传内存中文件(由 API 调用生成)

java - 公共(public)链部署

java - 为什么我的 JLabel 不能在循环中正确更新?

Java可执行jar logback-spring.xml没有看到logback.properties文件

c# - WCF 错误 : Cannot find a token authenticator

php - Zend 框架在哪里保存默认证书存储?

java - 如何从 LPRT ftp 命令获取 IPv6

c# - 使用带有临时文件名的 WinSCP .NET/COM 上传文件