Search code examples
javaftp-client

org.apache.commons.net.ftp.FTPClient : 530 Please login with USER and PASS


I want to visit a FTP server and get a directory list from the ftp server.So I use org.apache.commons.net.ftp.FTPClient to complete it. But the ftp server donn't need to login .so my code is like this

ftpClient.connect(ip, port);
ftpClient.changeWorkingDirectory(timePath);
FTPFile[] directoryArray = ftpClient.listFiles();

when I debug it ,there is no any error and exception. But I get nothing,then i find thisreplylines size = 1 530 Please login with USER and PASS. the FTP server doesn't have user and password to login.how can i solve it? thanks


Solution

  • Try logging in as anonymous ("anonymous" is the default user in many FTP servers):

    ftpClient.connect(ip, port);
    ftpClient.login("anonymous", "");
    ftpClient.changeWorkingDirectory(timePath);
    FTPFile[] directoryArray = ftpClient.listFiles();