www.jlion.com

Wednesday, November 18, 2009

I've occasionally encountered a problem with FTP, using either WS_FTP or applications that I've written that use the WININET libraries, that manifests itself as a timeout when downloading lots of (many hundreds or thousands) of files with FTP.

The FTP transfer process just seems to stop, with no discernible error. If disconnected then restarted (using WS_FTP) I am able to continue transferring files using FTP so no error with either my own or the server's network.

Today I happened upon what I think is the solution: "keep-alive". FTP uses two IP ports. One is a control connection, the other a random high number port, is used for actually sending data. It seems that the problem might be that the connection for the port used as a control connection is timing out and that the solution is to periodically send some data (a "ping") to the control connection on the server so that the server doesn't decide that the control connection is no longer needed and close it down.

Fortunately, this "keep alive" functionality is built into WS_FTP under the "advanced options" on the "site options" dialog. WS_FTP accepts a value in seconds between 10 and 3600 with a default is 0 (no keep-alive message). I tried changing this parameter in WS_FTP then executing a transfer that had been problematic for me in the past, and the transfer succeeded without issue.

It looks like the WININET library might also include support for keep alive. The HttpOpenRequest function supports a INTERNET_FLAG_KEEP_CONNECTION flag. This flag is described as causing the connection to "use keep-alive semantics, if available". I'm not sure if this is the same thing as WS_FTP's keep-alive option but it seems likely and I intend to try it out.

0 Comments:

Post a Comment

<< Home