【问题标题】:FTPClient Java speedup downloadFTPClient Java 加速下载
【发布时间】:2016-11-22 19:53:19
【问题描述】:

apaches FTPClient 1线程的最大下载速度是多少?

我无法通过 FPTSClient 连接 (AUTH SSL) 获得超过 6mb/s 的速度。 当我通过 FTP Rush 之类的 Ftp 工具连接时,我能够获得 150mb/s 甚至更多!

1,000.0M 字节,6.97 (150,376.60 KBps)

我已经尝试在 1024*1024 和 1024*1024*10 之间增加 ftpBufferSize,但没有任何改变。

这只是我连接到 ftp 的一个小 sn-p:

        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);

这里是最终下载的sn-p:

        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;
            }
        }

我需要传输大约 100MB 的大文件。有什么办法可以加快下载速度吗? 提前致谢,问候。

【问题讨论】:

  • 尝试使用BufferedOutputStream而不是接口OutputStream
  • 如果我将行 OutputStream output; 更改为 BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(tmpPath)); 我仍然需要 8 秒来获取 48mb 文件。所以这几乎是 6mb/s。没有变化,问候。

标签: java download ftp apache-commons ftp-client


【解决方案1】:

终于有办法了。 删除此行后:

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

达到 100MBps+ 没有问题。使用这条线,没有办法获得高于 6-7MBps 的速率。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-19
    • 2015-07-28
    • 2013-02-14
    • 1970-01-01
    • 2019-06-08
    • 2021-02-08
    • 2011-09-13
    • 2012-11-01
    相关资源
    最近更新 更多