Tôi đang sử dụng Apache Commons FTPClient để tải lên các tệp lớn, nhưng tốc độ truyền tải chỉ là một phần nhỏ của tốc độ truyền bằng WinSCP qua FTP. Làm thế nào tôi có thể tăng tốc độ chuyển giao của tôi?Tăng tốc Apache Commons FTPClient chuyển
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);
}
}
}
Apache phiên bản 3.3 gặp sự cố khi đặt BufferSize thành 0, vì nó sẽ sử dụng giá trị mặc định (8192) thay vì giá trị không giới hạn như mong đợi. – Thinhbk
Tôi đã phải cập nhật từ phiên bản 3.2 lên phiên bản 3.5 và nó hoạt động, nếu không vẫn còn chậm. Có lẽ 3,3 công trình mặc dù. – JohnyTex