Share on Google+Share on Google+

FTP Server: List all files name

This tutorial represents how to list the entire files name on FTP server using java.

FTP Server: List all files name 

This tutorial represents how to list all the files name on FTP server using java.

List all Files name:

We can list all the files name with the help of FTPClient class. FTPClient class provides different methods to operate the FTP server operations. There is no direct method to list only files of the ftp server. So first call method client.listFiles() to list all the files and directory and then check, it is file or not by using isFile() FTPFile method. Now you can display name of file by calling method file.getName().

Example : This example represents how to get list of files name.



class FTPListFiles {
	public static void main(String[] args) throws IOException {
		FTPClient client = new FTPClient();
		boolean result;
		try {
			result = client.login("admin", "admin");

			if (result == true) {
				System.out.println("User successfully logged in.");
			} else {
				System.out.println("Login failed!");
			FTPFile[] files = client.listFiles();
					.println("Files on Ftp Server : ");
			for (FTPFile file : files) {
				if (file.isFile()) {
					System.out.println("File name : " + file.getName());

		} catch (FTPConnectionClosedException e) {
		} finally {
			try {
			} catch (FTPConnectionClosedException e) {

Output :

User successfully logged in.
Files on Ftp Server : 
File name : ApacheServer.shtml
File name : FtpDownloadFile.shtml
File name : FtpFileTransfer.shtml
File name : FtpTest.txt
File name : newFtp.txt


Posted on: December 10, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: FTP Server: List all files name  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image