加快Apache Commons FTPClient传输速度 [英] Speed up Apache Commons FTPClient transfer

查看:436
本文介绍了加快Apache Commons FTPClient传输速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache Commons FTPClient上传大文件,但传输速度只是通过FTP使用WinSCP传输速度的一小部分。如何加快传输速度?

I am using Apache Commons FTPClient to upload large files, but the transfer speed is only a fraction of transfer speed using WinSCP via FTP. How can I speed up my transfer?

    public boolean upload(String host, String user, String password, String directory, 
        String sourcePath, String filename) throws IOException{

    FTPClient client = new FTPClient();
    FileInputStream fis = null;

    try {
        client.connect(host);
        client.login(user, password);
        client.setControlKeepAliveTimeout(500);

        logger.info("Uploading " + sourcePath);
        fis = new FileInputStream(sourcePath);        

        //
        // Store file to server
        //
        client.changeWorkingDirectory(directory);
        client.setFileType(FTP.BINARY_FILE_TYPE);
        client.storeFile(filename, fis);
        client.logout();
        return true;
    } catch (IOException e) {
        logger.error( "Error uploading " + filename, e );
        throw e;
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            client.disconnect();

        } catch (IOException e) {
            logger.error("Error!", e);
        }
    }         
}


推荐答案

增加缓冲区大小:

Increase the buffer size:

client.setBufferSize(1024000);

这篇关于加快Apache Commons FTPClient传输速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆