Speed up Apache Commons FTPClient transfer

前端 未结 4 1570
你的背包
你的背包 2021-01-04 10:33

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?<

相关标签:
4条回答
  • 2021-01-04 11:14

    It would be better if you use ftp.setbuffersize(0); if you use 0 as your buffersize , it will take as infinite buffer size. obviously ur transaction will get speeded up... I personally experienced it.. all the best... :)

    0 讨论(0)
  • 2021-01-04 11:29

    There is a known issued with Java 1.7 and Commons Net 3.2, the bug is https://issues.apache.org/jira/browse/NET-493

    If running these versions I'd suggest the upgrade to Commons Net 3.3 as the first step. Apparently 3.4 fixes more performance issues too.

    0 讨论(0)
  • 2021-01-04 11:32

    use the outputStream method, and transfer with a buffer.

    InputStream inputStream = new FileInputStream(myFile);
    OutputStream outputStream = ftpclient.storeFileStream(remoteFile);
    
    byte[] bytesIn = new byte[4096];
    int read = 0;
    
    while((read = inputStream.read(bytesIn)) != -1) {
        outputStream.write(bytesIn, 0, read);
    }
    
    inputStream.close();
    outputStream.close();
    
    0 讨论(0)
  • 2021-01-04 11:34

    Increase the buffer size:

    client.setBufferSize(1024000);
    
    0 讨论(0)
提交回复
热议问题