Apache Commons FTPClient.listFiles

前端 未结 7 1353
深忆病人
深忆病人 2020-12-15 05:48

I am using org.apache.commons.net.ftp.FTPClient in one of my applications to work with a FTP server. I am able to connect, login, pwd

7条回答
  •  無奈伤痛
    2020-12-15 06:38

    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;
    }
    

    }

提交回复
热议问题