commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kurniawan Kurt" <>
Subject RE: [Net] I'm having a problem using the listList files method in the FTPClient class
Date Mon, 23 May 2005 22:30:02 GMT


If you still need this.

This is the snippet of my code:

			FTPFile[] files = ftpClient.listFiles(directory);
			//iterate and collect !!
			for(int f=0;f<files.length;f++){
				log.debug("Filename: "+files[f].getName());
					log.debug("Add the file name: "+files[f].getName()+" to the list");
		}catch(IOException ioe){
			//TODO: log some error here
			log.error("The directory is not found or not a directory.",ioe);
			eAlert.setEmBody("The directory: "+directory+" is not found or not a directory in the source:

In you code, I realize you missed the closing curly bracket, I assume that just a cut-and-paste
The most important is that yo have to catch the exception for this, the listfiles method itself
throws exception.

Good luck

"What I hear, I forget. What I see, I remember.
And what I do, I understand."
~ Chinese Proverb

Kurt Kurniawan

-----Original Message-----
From: Daerian []
Sent: Sunday, 15 May 2005 1:31 PM
Subject: [Net] I'm having a problem using the listList files method in
the FTPClient class

I'm using FTPClient class to write an FTP client. I've searched some
examples on the internet of how to use the class methods. In the various
examples I've found the listFiles method is always used in the same way, but
when I try yo connect to an FTP server and use it I don't get any file. I've
tried several FTP servers and it happens in all of them, also, I've used
variants of the method, calling it with and without parameters. I've
successfuly changed the working directory to a directory that I know that
contains files and it still does not work. This is the piece of code:

 FTPClient f= new FTPClient();

 FTPFile[] files = f.listFiles();
System.out.println("Number of files in the directory: " + files.length);
 for(int i=0;i< files.length;i++){
 System.out.println("files:" + files[i].getName());

I can't find why it does not work. If someone could point me the error I
would appreciate it.


CAUTION: This email and files included in its transmission
are solely intended for the use of the addressee(s) and may
contain information that is confidential and privileged.
If you receive this email in error, please advise us
immediately and delete it without copying the contents
contained within. Woolworths Limited (including its group
of companies) do not accept liability for the views
expressed within or the consequences of any computer
viruses that may be transmitted with this email. The
contents are also subject to copyright. No part of it
should be reproduced, adapted or transmitted without the
written consent of the copyright owner.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message