commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julien Aymé" <julien.a...@gmail.com>
Subject [Net]Re: Question regarding FTPClient.retrieve
Date Tue, 17 Jul 2007 08:32:29 GMT
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_fard_2000@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


Mime
View raw message