Commons FTPClient freezes after loading a large file

I use Apache Commons FTPClient 3.1 for easy file uploads. The storefile () file works fine for smaller files (up to 100 MB), but when I try to download something larger than 100 MB, it will complete the download, but just hang.

I tried to enter passive mode, as others suggested, but it seems that the problem is not resolved. I tried several FTP servers with the same results, so I assume this is not a host.

Here is the gist of what I'm doing:

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

The program freezes on line 4 for large files, but successfully loads the file.

+2
source share
1 answer

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

Waiting time. This link may help.

Control Channel Maintain Function: During the file transfer, the data connection is busy, but the control connection is not working. FTP servers know that a control connection is being used, so it will not close it due to inactivity, but it is much more difficult for network routers to know that the management and data connections are connected to each other. Some routers may treat the management connection as idle and disconnect it if data transfer over the connection takes longer than the idle timeout for the router. One solution to this is to send a secure command (i.e., NOOP) over the control connection with the reset router idle timer. This is activated as follows:

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

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

+6
source

All Articles