xuyl
V2EX  ›  Java

java 通过 ftp 连接 windows 下的 serv-u,怎么实现目录的遍历?

  •  
  •   xuyl · Jun 16, 2015 · 3309 views
    This topic created in 4012 days ago, the information mentioned may be changed or developed.
    //若ftp服务端是linux下的vsftp,下面的代码可以实现遍历
    String ftpDirectory = "/data/ftp/xxx/";
    try {
        DataInputStream dis = new  DataInputStream(ftpClient.nameList(ftpDirectory));
        String filename = "";
        while ((filename = dis.readLine()) != null) {
                    System.out.println(filename);
        }
    } catch (Exception e) {
                e.printStackTrace();
    }
    

    而在windows下,不知道是否目录写法的原因

    String ftpDirectory = "/xxx/"; //这里是把ftp帐号的目录设在D:\www下,所以都用相对目录来设置ftp目录的。
    其他同,Run一下,Console下面报错:NLST /: 550 No Files found.

    求指导。

    1 replies    2015-06-16 09:10:42 +08:00
    iam36
        1
    iam36  
       Jun 16, 2015
    你要参考两个来源:

    1、FTP的RFC协议,应该是ls或者dir,然后按属性处理
    2、SERV-U的command扩展,具体参照到其帮助文档
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1047 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 22:56 · PVG 06:56 · LAX 15:56 · JFK 18:56
    ♥ Do have faith in what you're doing.