You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Payam Fard <p_...@yahoo.com> on 2007/07/16 20:37:55 UTC
Question regarding FTPClient.retrieve
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();
____________________________________________________________________________________
TV dinner still cooling?
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
[Net]Re: Question regarding FTPClient.retrieve
Posted by Julien Aymé <ju...@gmail.com>.
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 <p_...@yahoo.com>:
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org