如何在连接Apache FTPSClient后记录“220 server ready”消息

时间:2016-01-23 01:50:38

标签: java ftp ftps apache-commons-net

我正在使用Apache Commons Net编写一个简单的FTPS客户端。一切正常,但最初的“服务器就绪”消息未被记录。我呼叫connect()并立即执行getReplyString(),所有日志都是234 Enabling TLS, awaiting negotiations,即使我知道服务器在连接后正在发送消息:

220 FTPS (Version Fri Jan 22 19:49:50 2016) server ready.

我甚至使用getReplyStrings()来查看是否有多条消息,但它仍然只显示一条234 Enabling TLS, awaiting negotiations消息。我有一种感觉,因为这是我连接(显式TLS)时自动发出的AUTH TLS命令的唯一回复。

我做了一个破解ProtocolCommandListener输出并以这种方式抓取消息的黑客,但我宁愿正确地做。我有一种感觉,我错过了一些简单的东西。有人可以帮忙吗?

代码:

FTPSClient ftpsclient = new FTPSClient("TLSv1.2");

// my hacked attempt to get the message
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos,true,"utf-8");
ftpsclient.addProtocolCommandListener(new PrintCommandListener(ps, true));

logMessage("Connecting to FTP-SSL server [" + HOST + "] on port [" + PORT + "]...", 1);
ftpsclient.connect(HOST, PORT);
_logger.debug("Output: "+ baos.toString()); 
if (!FTPReply.isPositiveCompletion(ftpsclient.getReplyCode())) {
    throw new Exception("Failed to connect to [" + HOST + "]\n" + ftpsclient.getReplyString());
}
logMessage(ftpsclient.getReplyString(), 1);

输出:

[Jan 22, 16:49:50] INFO logMessage() - Connecting to FTP-SSL server [HOST] on port [PORT]...
[Jan 22, 16:49:55] DEBUG - Output: 220 FTPS (Version  Fri Jan 22 19:49:50 2016) server ready.
AUTH TLS
234 Enabling TLS, awaiting negotiations.
[Jan 22, 16:49:55] INFO  EDIDataExtractor.logMessage() - 234 Enabling TLS, awaiting negotiations.

0 个答案:

没有答案