commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kurt Kurniawan" <>
Subject [NET] Error in retrieving more than one file.
Date Mon, 28 Feb 2005 22:48:08 GMT

Hello all,

We have this code, where we're trying to pickup more than one file in the remote machine and
put locally.
But I always get the value of ios=null on the second iteration when it's trying to pick up
the second file.

The FtpClient seems to be still connected.

I can reconnect and pick that file again, but that is not an efficient way to do.

Is there any  reasons why is this happened ? Can anyone give me some hints of what happened

The code is just examples of what my project does, I have to do this in this way instead of
using retrieveFile(java.lang.String remote, local), because I need it
to return as InputStream.

Thank you for any help.



public class ExperimentFTP {

	public static void main(String[] args) {
		System.out.println("Start process");
		Log log=LogFactory.getLog(ExperimentFTP.class);
		String directory="/usr/egate/tst";
		String fileregex="rm_lo_ftp*";
		Vector filesV=new Vector();
		Pattern ptrn=Pattern.compile(fileregex);
		Matcher match;
		FileOutputStream fos;
		FTPClient ftp=new FTPClient();
			FTPFile[] files = ftp.listFiles(directory);
			//iterate and collect !!
			for(int f=0;f<files.length;f++){
				//log filename here !!
				log.debug("Filename: "+files[f].getName());
				//log --if any match then add to list.
					log.debug("Add the file name: "+files[f].getName()+" to the list");
			//now try to pick up the file and send.
			Enumeration e=filesV.elements();
				String fileElement=(String)e.nextElement();
				log.debug("Writing the file: "+fileElement);
				InputStream ios=ftp.retrieveFileStream(fileElement);
				fos = new FileOutputStream("c:/myDir/"+fileElement);
				//write to the file
				byte[] buffer=new byte[4096]; //byte to hold the content make it 4KB at one read
				int bytes_read; //number of bytes in buffer
				log.debug("Writing the file");
		}catch(IOException e){
			log.error("There is error in the process ",e);

CAUTION: This message may contain confidential information intended only for the use of the
addressee named above. If you are not the intended
recipient of this message, any use or disclosure of this message is prohibited. If you received
this message in error please notify email Administrators immediately.  You must obtain all
necessary intellectual property clearances before doing anything other than displaying this
message on your monitor. There is no intellectual property licence.  Any views expressed in
this message are those of the individual sender and may not necessarily reflect the views
of BIG W Discount Stores.

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

View raw message