LucasLee92
V2EX  ›  Java

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

  •  
  •   LucasLee92 · Jun 13, 2018 · 3074 views
    This topic created in 2921 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   ·   3271 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 118ms · UTC 10:38 · PVG 18:38 · LAX 03:38 · JFK 06:38
    ♥ Do have faith in what you're doing.