JPL JPL - 3 years ago 213
Apache Configuration Question

Commons FTPClient hangs after uploading large a file

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:

boolean success = ftpClient.storeFile(...);

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download