You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Jeremy Weatherford <je...@neteamavi.com> on 2006/11/06 19:28:31 UTC

FTPClient and incomplete downloads?

Hello,

I just discovered that FTPClient is having problems with larger files being
retrieved incompletely.  An example file retrieved via FileZilla and
FTPClient (both in binary mode) had:

FileZilla size:	282,843,303 bytes
FTPClient size:	282,838,183 bytes

Obviously this causes a problem.  The relevant code is:

        FTPClient cli = new FTPClient();

        try {
            cli.connect(enc.ip);
            int reply = cli.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                cli.disconnect();
                error("Connection refused."); return;
            }
            if (!cli.login("user", "pass") {
                error("Bad user/password"); return;
            }
            cli.setFileType(FTP.BINARY_FILE_TYPE);
            
            try {
                FTPFile[] files = cli.listFiles(filename);
                sizekbytes = files[0].getSize() / 1024;
                System.out.println(filename + " is " + sizekbytes + " KB");
            } catch (Exception e) {}
            
            status = "Transferring...";
            os = new FileOutputStream(destination + "\\" + filename);
            if (!cli.retrieveFile(filename, os)) {
                error("Could not retrieve file."); return;
            }
            
            os.close();
        } catch (Exception e) {
            if (cli.isConnected()) try { cli.disconnect(); } catch
(Exception e2) {}
            error("FTP exception: " + e.getMessage());
        }

The only other strange thing I'm doing is periodically interrogating the
OutputStream's position from another thread for progress reporting: 

	long pos = os.getChannel().position() / 1024;

The banner at the server is "220 Microsoft FTP Service", and the OS is
Windows 2003.  Client OS is Windows XP.

Any ideas?  I really like some of the features offered by this library, but
this is a huge problem.

Thanks,
Jeremy