gpt4 book ai didi

java - 加速 Apache Commons FTPClient 传输

转载 作者:搜寻专家 更新时间:2023-10-30 21:15:51 24 4
gpt4 key购买 nike

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

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

最佳答案

增加缓冲区大小:

client.setBufferSize(1024000);

关于java - 加速 Apache Commons FTPClient 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11572588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com