Java – accelerate Apache Commons ftpclient transfer
•
Java
I use Apache Commons ftpclient to upload large files, but the transfer speed is only a small part of the transfer speed through FTP using winscp How can I speed up the transfer?
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); } } }
Solution
Increase buffer size:
client.setBufferSize(1024000);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码