Hello payam,

   I think this kind of questions belongs to the commons-user list
rather than the commons-dev list, but it's not a big deal.
   I think you should make sure that the connection to the FTP server
is complete (try the code below); and you should make sure that the
remoteFilename is either the absolute path in the FTP server to your
file, or a path to your file relative to the current directory in the
FTPClient (try the printWorkingDirectory() and listFiles() methods).


boolean result;
try {
   ftp.connect(myHostname);
   if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
       throw new IOException("Cannot connect to "+myHostname);
   }
   if (!ftp.login(myUsername, myPassword)) {
       ftp.disconnect();
       throw new IOException("Wrong username/password");
   }

   File localFile = new File("C:\\test\\test.csv");
   FileOutputStream outStream = new
FileOutputStream(localFile.getAbsoluteFile());
   result = ftp.retrieveFile(remoteFilename, outStream);
   ftp.logout();
} finally {
   ftp.disconnect();
}

I hope this helps,
Julien

2007/7/16, Payam Fard <[EMAIL PROTECTED]>:
I am using FTPClient class and would like to download
a file from an FTP site. Here is what I am doing, but
I cannot get it to download the file. Any help would
be appreciated:

ftp.connect(myHostname);

ftp.login(myUsername, myPassword);

File localFile = new File("C:\\test\\test.csv");

FileOutputStream outStream = new
FileOutputStream(localFile.getAbsoluteFile());

boolean result = ftp.retrieveFile(remoteFilename,
outStream);

ftp.disconnect();


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to