問題描述
Apache Commons Net 庫似乎沒有向任何記錄器"發送任何內容.
Apache Commons Net library does not seem to send anything to any "logger".
我能否以某種方式從 (FTP) 會話中獲取日志文件以進行調試?例如來自服務器的原始 FTP 命令和響應,如下所示:
Can I somehow obtain a log file from an (FTP) session, for debugging purposes? For example raw FTP commands and responses from the server, like this:
220 Welcome
USER *******
331 Password required for ...
PASS *******
230 Logged on
TYPE I
200 Type set to I
QUIT
221 Goodbye
推薦答案
Apache Commons Net 中的所有協議實現,包括 FTPClient
,都派生自 SocketClient
,它有一個方法<代碼>addProtocolCommandListener.您可以將 ProtocolCommandListener
實現日志記錄.
All protocol implementations in Apache Commons Net, including FTPClient
, derive from SocketClient
, which has a method addProtocolCommandListener
. You can pass it an implementation of ProtocolCommandListener
to implement logging.
有一個現成的實現 PrintCommandListener
,將協議日志打印到提供的PrintStream
.
使用這樣的代碼:
ftpClient.addProtocolCommandListener(
new PrintCommandListener(
new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")), true));
...,您將得到您所要求的準確輸出.
..., you will get exactly the output that you have asked for.
這篇關于在 Apache Commons Net 中為 FTP 協議啟用日志記錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!