You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Bo...@thomson.com on 2004/12/30 17:52:37 UTC

[net] FTPClient retrieveFileStream/completePendingCommand question

I am using FTPClient to transfer a file from a remote machine to my local machine.  I am calling the retrieveFileStream() method to transfer the file.  From the documentation, I know that I must complete the command by calling completePendingCommand().  However, completePendingCommand() hangs unless I first close the input stream returned from retrieveFileStream().  After stepping through the code (which doesn't close the input stream), I can see that the completePendingCommand() is hanging because it is trying to read the "226 Transfer complete" reply from the FTP server, but the server doesn't send this reply until after the data connection input stream is closed.  Can someone please help me understand why the input stream must be closed before the FTP server will send a "226 Transfer complete" reply?  The data has all been transferred to the input stream at the time I call completePendingCommand() (whether I close the input stream or not).

Here is a piece of my test code.  If I leave out the fis.close() call, the completePendingCommand() call hangs.  If I leave it in, it prints "success".


           InputStream fis = null;
           fis = ftp.retrieveFileStream(remote);
           fis.close();  // leave this in -- success, take it out -- hangs
            if(!ftp.completePendingCommand())
            {
               System.out.println("Failed at ftp completependingcommand");
            }
            else
            {
               System.out.println("success");
            }
 
Thanks very much.
Bonnie Zeller


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org