Apache Commons FTPClient.listFiles

狂风中的少年 提交于 2019-11-30 06:13:17
PapaFreud

This seems like the same issue I had (and solved), see this answer:

Apache Commons Net FTPClient and listFiles()

After I set the mode as PASV it is working fine now! Thanks for all your efforts and suggestions!

Just a silly suggestion... can you do a listing on the /uploads folder using a normal FTP client. I ask this because some FTP servers are setup to not display the listing of an upload folder.

First, make sure the listing works in other programs. If so, one possibility is that the file listing isn't being parsed correctly. You can try explicitly specifying the parser to use with initiateListParsing.

I had to same problem and it turned out to be that it couldn't parse what the server was returning for a file listing. I this line after connecting to the ftp server ftpClient.setParserFactory(new MyFTPFileEntryParserFactory());

public class MyFTPFileEntryParserFactory implements FTPFileEntryParserFactory {
private final static FTPFileEntryParser parser = new UnixFTPEntryParser() {
    @Override public FTPFile parseFTPEntry(String entry) {
        FTPFile ftpFile = new FTPFile();
        ftpFile.setTimestamp(getCalendar(entry));
        ftpFile.setSize(get(entry));
        ftpFile.setName(getName(entry));
        return ftpFile;
    }
};

@Override public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException {
    return parser;
}

@Override public FTPFileEntryParser createFileEntryParser(String key) throws ParserInitializationException {
    return parser;
}

}

I added client.enterLocalPassiveMode() and it works:

client.connect("xxx.com");
boolean login = client.login("xxx", "xxx");
client.enterLocalPassiveMode();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!