Speed up Apache Commons FTPClient transfer

前端 未结 4 1571
你的背包
你的背包 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: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();
    

提交回复
热议问题