LucasLee92
V2EX  ›  Java

如何把 FTPSClient 的调用的实际命令输出到日志

  •  
  •   LucasLee92 · Jun 13, 2018 · 3011 views
    This topic created in 2893 days ago, the information mentioned may be changed or developed.

    使用org.apache.commons.net.ftp.FTPSClient作为 ftp 客户端上传文件, 通过调用 client 对象的 addProtocolCommandListener 可以把 client 调用的 ftp 命令输出到一个写出流, 这里我选择的是输出到控制台ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));, 但实际项目需要输出到日志, 到这一步就卡住无法实现,不知道有人有什么好的想法吗~~

    1 replies    2020-06-22 16:49:57 +08:00
    TeeMoCode
        1
    TeeMoCode  
       Jun 22, 2020
    可以自己实现 org.apache.commons.net.ProtocolCommandListener 接口,
    比如实现类叫做 LoggerCommandListener,
    那么添加 CommandListener 就可以写成
    ftp.addProtocolCommandListener(new LoggerCommandListener(org.slf4j.LoggerFactory.getLogger(xx.class), true));
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2858 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 01:28 · PVG 09:28 · LAX 18:28 · JFK 21:28
    ♥ Do have faith in what you're doing.