Search code examples
javadownloadftpapache-commonsftp-client

FTPClient Java speedup download


What is the max download-speed with 1 thread of apaches FTPClient?

I'm not able to get more, than about 6mb/s with an FPTSClient connection (AUTH SSL). When i connect via an Ftp Tool like FTP Rush im able to get 150mb/s and more!

1,000.0M byte(s) in 6.97 (150,376.60 KBps)

I've already try to increase the ftpBufferSize between 1024*1024 and 1024*1024*10, but nothing changed.

This is just a small snippet where i connect to the ftp:

        ftp.setConnectTimeout(8000);
        ftp.setDefaultPort(this.port);
        try {
            ftp.connect(this.host);
        } catch (Exception e) {
            LogController.logMessage("Connect::tryConnect -> Exception: "+e.getMessage());
            LogController.logMessage(e);
        }

        if(ftp.isConnected()) {

            if(this.ssl) {
                ((FTPSClient) ftp).execPBSZ(0);
            }

            LogController.logMessage("Connect::tryConnect -> Open new connection.");
            if(!ftp.login(this.username, this.password)) {
                LogController.logMessage("Connect::tryConnect -> "+getReplyString());
                ftp.logout();
            } else {
                LogController.logMessage("Connect::tryConnect -> User login correct.");
                if(this.ssl) {
                    ((FTPSClient) ftp).execPROT("P");
                    LogController.logMessage("Connect::tryConnect -> "+getReplyString());
                }

                if(ftp.getSystemType().toLowerCase().contains("win") == false)
                    ftp.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));


                int reply = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    LogController.logMessage(getReplyString());
                } else {

                    ftp.enterLocalPassiveMode();
                    ftp.setBufferSize( 10485760 );
                    ftp.setRemoteVerificationEnabled(false);
                    ftp.setListHiddenFiles(true);

And here is the final download snippet:

        if ( download ) {                   
            OutputStream output;
            output = new FileOutputStream(tmpPath);

            if(!ftp.setFileType(FTP.BINARY_FILE_TYPE))
                LogController.logMessage("Connect::downloadFiles -> Could'nt set binary file type.");

            DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            Date d = new Date();
            String date = dateFormat.format(d);
            LogController.logMessage("Connect::downloadFiles -> Start downloading "+file+", "+date+", Buffersize: "+ftp.getBufferSize());

            if(!ftp.retrieveFile(ftpFilePath, output)) {
                LogController.logMessage("Connect::downloadFiles -> Could'nt download the file: "+file);
                output.close();
                return false;
            } else { 
                output.close();
                d = new Date();
                date = dateFormat.format(d);
                LogController.logMessage("Connect::downloadFiles -> Download finished. "+date);
                return true;
            }
        }

I need to transfer large files about 100MB. Is there any way to speed up the download? Thanks in advance, regards.


Solution

  • Finally got a solution. After removing this line:

    ((FTPSClient) ftp).execPROT("P");
    

    There was no problem to reach 100MBps+. With this line there was no way to get higher rate than 6-7MBps, regards.