java – 加速Apache Commons FTPClient传输
发布时间:2020-12-14 05:28:38 所属栏目:Java 来源:网络整理
导读:我使用Apache Commons FTPClient来上传大文件,但传输速度只是使用WinSCP通过FTP传输速度的一小部分.我如何加快转帐? public boolean upload(String host,String user,String password,String directory,String sourcePath,String filename) throws IOExcept
我使用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); } } } 解决方法
增加缓冲区大小:
client.setBufferSize(1024000); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |