Commons FTPClient hangs after uploading large a file

谁说胖子不能爱 提交于 2019-12-01 06:53:29

问题


I'm using Apache Commons FTPClient 3.1 to do a simple file upload. storefile() works fine for files of smaller sizes (under 100MB), but when I try uploading something greater than 100MB, it would finish uploading but just hang.

I've tried entering passive mode like others have suggested, but it doesn't seem to fix the problem. I've tried multiple FTP servers with the same results, so I'm guessing it's not the host.

Here's the gist of what I'm doing:

ftpClient.connect(...);
ftpClient.login(...);
ftpClient.enterLocalPassiveMode();
boolean success = ftpClient.storeFile(...);
if(success)
...

The program hangs at line 4 for large files, but does successfully upload the file.


回答1:


https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html

Its timing out. This link may help.

Control channel keep-alive feature: During file transfers, the data connection is busy, but the control connection is idle. FTP servers know that the control connection is in use, so won't close it through lack of activity, but it's a lot harder for network routers to know that the control and data connections are associated with each other. Some routers may treat the control connection as idle, and disconnect it if the transfer over the data connection takes longer than the allowable idle time for the router. One solution to this is to send a safe command (i.e. NOOP) over the control connection to reset the router's idle timer. This is enabled as follows:

 ftpClient.setControlKeepAliveTimeout(300); // set timeout to 5 minutes

This will cause the file upload/download methods to send a NOOP approximately every 5 minutes.



来源:https://stackoverflow.com/questions/10530240/commons-ftpclient-hangs-after-uploading-large-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!