[英]Enable logging in Apache Commons Net for FTP protocol
Apache Commons Net library does not seem to send anything to any "logger". Apache Commons Net 库似乎没有向任何“记录器”发送任何内容。
Can I somehow obtain a log file from an (FTP) session, for debugging purposes?我可以以某种方式从(FTP)会话中获取日志文件以进行调试吗? For example raw FTP commands and responses from the server, like this:
例如来自服务器的原始 FTP 命令和响应,如下所示:
220 Welcome
USER *******
331 Password required for ...
PASS *******
230 Logged on
TYPE I
200 Type set to I
QUIT
221 Goodbye
All protocol implementations in Apache Commons Net, including FTPClient
, derive from SocketClient
, which has a method addProtocolCommandListener
. Apache Commons Net 中的所有协议实现,包括
FTPClient
,都源自SocketClient
,它有一个addProtocolCommandListener
方法。 You can pass it an implementation of ProtocolCommandListener
to implement logging.您可以将
ProtocolCommandListener
的实现传递给它来实现日志记录。
There's a ready-made implementation PrintCommandListener
, which prints the protocol log to provided PrintStream
.有一个现成的实现
PrintCommandListener
,它将协议日志打印到提供的PrintStream
。
With a code like this:使用这样的代码:
ftpClient.addProtocolCommandListener(
new PrintCommandListener(
new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")), true));
..., you will get exactly the output that you have asked for. ...,您将获得您要求的准确输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.