commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tom Werges" <>
Subject [net] FTPClient.retrieveFileStream returns null even when no error is encountered
Date Tue, 21 Dec 2004 06:45:15 GMT
The FTPClient.retrieveFileStream method is returning null on all invocations
after the first one on the same connection. The javadoc indicates that a
null will only be returned in case of an error, in which case I can check
the reply code for the exact problem. But the reply code indicates that
everything went fine with no errors, and a null is still returned.

The retrieveFile method works properly even if I call it repeatedly. However
the retrieveFile method is not suitable for my purposes because I require an
InputStream for updating a gui.

I haven't entered this into the bug database yet because I'm assuming I'm
making an elementary mistake. However I was not able to find any information
on this issue in the mailing list archives or in the FAQ.

The code is as follows:

InputStream is = null;
OutputStream os = null;

for (TransferItem item : xferItems) {

  try {
    os = new FileOutputStream(new File(item.getLocalPath())); //local

    // retrieveFile method WORKS PROPERLY:
    //    ftpClient.retrieveFile(item.getServerPath(), os);

    // however, retrieveFileStream (following) does not work properly:

    is = ftpClient.retrieveFileStream(item.getServerPath());
    System.out.printf("Retrieve file [%s], code:%s, reply:%s",
    if (is == null) {
        System.out.println("InputStream was null! Skipping...");
    copyStream(is, os);

  } finally {
    if (is != null) is.close();
    if (os != null) os.close();

The initial invocation works fine, after which I always get a null plus a
message that everything is fine.

One possibly relevant detail is that the reply codes are not always the
same. The first invocation has a reply code of 150 ("Opening BINARY mode
data connection"), whereas the second has 200 ("PORT command successful.
Consider using PASV."). Subsequent invocations yield 150 once again.

I'm using jdk1.5 on linux connecting to a vsftp server on linux.

Thanks for any help,
Tom W

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

View raw message