Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I am trying to get Filelist from ftp server using org.apache.commons.net.ftp.FTPClient but I Can't get File list from server.
I am posting my code please suggest me where I missed any step.

Thanks in Advance

C#
public static void main(String[] args) {
		FTPClient client = new FTPClient();
		try {
			client.connect("192.168.1.9",5001);
			String[] flist = client.listNames();
			for (String file : flist)
				System.out.println(file);
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}
Posted

Java
import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPFile;

public class BasicFTP {

    public static void main(String[] args) throws IOException {
        FTPClient client = new FTPClient();
        client.connect("c64.rulez.org");
        client.enterLocalPassiveMode();
        client.login("anonymous", "");
        FTPFile[] files = client.listFiles("/pub");
        for (FTPFile file : files) {
          if (file.getType() == FTPFile.FILE_TYPE)
            System.out.println(file.getName());
        }
    }
}

and use commons-net-ftp-2.0.jar
 
Share this answer
 
v2
Comments
Shruti91 31-Dec-15 1:17am    
It works. Thank you for your valuable response.
Can you try below code to get list of files

FTPFile[] ftpFiles = client.listFiles();
 
Share this answer
 
Comments
Shruti91 29-Dec-15 7:19am    
it returns The import org.apache.oro cannot be resolved
even if I added oro-2.0.8.jar reference.
rah_sin 29-Dec-15 7:22am    
The import should be

import org.apache.commons.net.ftp.FTPFile;
Shruti91 29-Dec-15 7:29am    
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The import org.apache.oro cannot be resolved

this error shown in Console
rah_sin 29-Dec-15 7:38am    
Kindly use appropriate commons appache jar which have FTPClient class file.
Shruti91 29-Dec-15 7:51am    
Can you provide me link to download jar file, Please.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900