Apache Commons Net库似乎没有向任何“logger”发送任何内容。
我可以以某种方式从(FTP)会话中获取日志文件,以进行调试吗?例如,来自服务器的原始FTP命令和响应,如下所示:
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
实现以实现日志记录。
有一个现成的实现PrintCommandListener
,它打印协议日志以提供PrintStream
。
使用这样的代码:
ftpClient.addProtocolCommandListener(
new PrintCommandListener(
new PrintWriter(new OutputStreamWriter(System.out, "UTF-8")), true));
...,您将获得您所要求的输出。