简体   繁体   English

apache commons ftp连接纯文本但授权SSL

[英]apache commons ftp connect plaintext but authorize SSL

I am attempting to use Apache Commons Net library to connect to an FTP server where the initial connection is plain text (and the file listings), but the authorization and data transfer are SSL. 我正在尝试使用Apache Commons Net库连接到FTP服务器,该服务器的初始连接为纯文本(和文件列表),但授权和数据传输为SSL。 I've verified using CoreFTP that this is the actual behavior of the server. 我已使用CoreFTP验证这是服务器的实际行为。 How can I accomplish this with the Apache Commons library. 如何使用Apache Commons库完成此操作。

If I use a plain FTPClient I can get a connection but then I get this message: 503 USER: Server policy requires that all clients be secured. 如果我使用普通的FTPClient,则可以建立连接,但是却收到以下消息:503 USER:服务器策略要求所有客户端均受保护。

If I try a FTPSClient this way 如果我这样尝试FTPSClient

 FTPSClient l_ftp = new FTPSClient("SSL", true); l_ftp.setAuthValue("SSL"); l_ftp.connect(l_host, l_port); 

I get this error: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 我收到此错误:javax.net.ssl.SSLException:无法识别的SSL消息,纯文本连接?

which makes a bit of sense, as the server is expecting a plain text connection and the client is attempting SSL. 这很有道理,因为服务器期望纯文本连接,而客户端正在尝试SSL。

If I try this 如果我尝试这个

 FTPSClient l_ftp = new FTPSClient("SSL", false); l_ftp.setAuthValue("SSL"); l_ftp.connect(l_host, l_port); 

I get this: 我得到这个:

 javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake Caused by: java.io.EOFException: SSL peer shut down incorrectly 

which I think probably means about the same, server expecting plain text and client expecting SSL. 我想大概意味着相同,服务器期望纯文本,客户端期望SSL。

Is this even possible with the Apache Commons library? Apache Commons库甚至有可能吗?

Here is the CoreFTP Log 这是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 

This turned out to be some kind of library or some other conflict in the application server I was running in. When I pulled my test code out to a standalone project, it worked fine. 原来这是我正在运行的应用程序服务器中的某种库或其他冲突。当我将测试代码提取到一个独立项目中时,它运行良好。 For posterity sake, here is the working code. 为了后代,这是工作代码。

 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(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM