300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > java ftpclient限速 加快Apache Commons FTPClient传输

java ftpclient限速 加快Apache Commons FTPClient传输

时间:2022-08-23 22:23:51

相关推荐

java ftpclient限速 加快Apache Commons FTPClient传输

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

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

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。