Apache Commons FTPClient.listFiles

前端 未结 7 1350
深忆病人
深忆病人 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:26

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

    Apache Commons Net FTPClient and listFiles()

    0 讨论(0)
  • 2020-12-15 06:28

    I added client.enterLocalPassiveMode() and it works:

    client.connect("xxx.com");
    boolean login = client.login("xxx", "xxx");
    client.enterLocalPassiveMode();
    
    0 讨论(0)
  • 2020-12-15 06:36

    In my case, on top of applying enterLocalPassiveMode and indicating correct operation system, I also need to set UnparseableEntries to true to make the listFile method work.

    FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
    conf.setUnparseableEntries(true);
    f.configure(conf);
    boolean isLoginSuccess = client.login(username, password);
    
    0 讨论(0)
  • 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;
    }
    

    }

    0 讨论(0)
  • 2020-12-15 06:39

    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.

    0 讨论(0)
  • 2020-12-15 06:42

    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.

    0 讨论(0)
提交回复
热议问题