我正在尝试使用Apache Commons Net库连接到初始连接是纯文本(和文件列表)的FTP服务器,但授权和数据传输是SSL。我已经使用CoreFTP验证了这是服务器的实际行为。如何使用Apache Commons库完成此任务。
如果我使用普通的FTPClient,我可以获得连接,但后来收到此消息:503 USER:服务器策略要求所有客户端都受到保护。
如果我以这种方式尝试FTPSClient
FTPSClient l_ftp = new FTPSClient("SSL", true); l_ftp.setAuthValue("SSL"); l_ftp.connect(l_host, l_port);
我收到此错误:javax.net.ssl.SSLException:无法识别的SSL消息,明文连接?
这有点意义,因为服务器期望纯文本连接并且客户端正在尝试SSL。
如果我试试这个
FTPSClient l_ftp = new FTPSClient("SSL", false); l_ftp.setAuthValue("SSL"); l_ftp.connect(l_host, l_port);
我明白了:
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake Caused by: java.io.EOFException: SSL peer shut down incorrectly
我认为可能意味着相同,服务器期望纯文本和客户期望SSL。
Apache Commons库是否可以实现这一点?
这是CoreFTP日志
Welcome to Core FTP, release ver 2.2, build 1857 (x64) -- © 2003-2014 WinSock 2.0 Mem -- 2,096,632 KB, Virt -- 8,589,934,464 KB Started on Monday October 26, 2015 at 14:18:PM Resolving nnnnnnn.nnnnn.com... Connect socket #900 to 222.222.222.222, port 21... 220 CONNECT:Enterprise Gateway 2.0.02. S48 FTP Server ready... 15:18:25 10-26-2015 AUTH SSL 234 AUTH: command accepted. Securing command channel ... TLSv1, cipher TLSv1/SSLv3 (RC4-MD5) - 128 bit USER omitted 331 Password required for omitted. PASS ********** 230 User omitted logged in. Session Id: 25846. PBSZ 0 200 PBSZ command accepted. PROT C 534 PROT Request denied for policy reasons. PROT cmd failed... CCC 200 CCC command channel is no longer secured. SYST 502 Command not implemented. Keep alive off... PWD 257 "omitted" is the current working Mailbox ID. PASV 227 PASV Entering passive mode (209,95,224,76,121,95). LIST Connect socket #940 to 209.95.224.76, port 31071... 150 Opening data connection. 226 Transfer complete. 0 Bytes sent. Transferred 0 bytes in 0.008 seconds
答案 0 :(得分:0)
这在我运行的应用程序服务器中是某种类型的库或其他冲突。当我将测试代码拉到一个独立的项目时,它工作正常。为了后人,这是工作代码。
FTPSClient l_ftp = new FTPSClient("SSL", false); l_ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); l_ftp.setAuthValue("SSL"); l_ftp.connect(l_host, l_port); if (!l_ftp.login(l_username, l_password)) { // BAD! } l_ftp.execPBSZ(0L); l_ftp.execCCC(); l_ftp.pwd(); // DO STUFF l_ftp.logout(); l_ftp.disconnect();