开发者

Using threading to keep FTP control port alive

My FTP download script (based on ftplib) is hanging on large downloads. The remote server I'm working with, while highly configurable (proftpd) is unable to get passed the firewall limitations imposed by the remote network.

I am restricted to 开发者_开发问答using passive mode at my company, i.e. IT will not open a port for me to allow FTP active mode.

So, I'm stuck with passive mode.

The remote server gets disconnected 10 to 15 minutes in to a large download.

I NEED TO keep the control connection alive during a large download. Should I use threading, sending a 'NOOP' command every ten seconds? If so, would you kind souls send me some example code that would do the trick? I need to pass multiple values to my FTP download function. The keepalive function would not need any parameters passed to it.

Or, is there a way to control the specific socket that I'm using on port 21 (control connection) to keep it alive while the large download takes place on port nnnnnn?

Thanks much!


You might also try to use the TCP KeepAlive feature by adding this code:

import socket
ftp.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

The support of the TCP KeepAlive is highly platform and firewall dependent - thus no guarantee, but it is designed for this purpose and it would be a lot simpler than adding an additional thread. On which platforms are you working?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜