使用线程来保持FTP控制端口活着 [英] Using threading to keep FTP control port alive

查看:119
本文介绍了使用线程来保持FTP控制端口活着的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的FTP下载脚本(基于ftplib)挂在大量下载中。我正在使用远程服务器,而高度可配置(proftpd)无法通过远程网络施加的防火墙限制。



我仅限于在我的公司使用被动模式,即IT不会为我打开端口以允许FTP活动模式。



所以,我坚持被动模式。



远程服务器在10到15分钟内断开大量下载。

我需要在大量下载期间保持控制连接的存在。我应该使用线程,每隔10秒发送一次'NOOP'命令吗?如果是这样,你会友善地给我发送一些示例代码来做到这一点吗?我需要将多个值传递给我的FTP下载功能。 Keepalive函数不需要传递给它的任何参数。

或者,有没有办法控制我在端口21上使用的特定套接字(控制连接)保持它活着,而大型下载发生在港口nnnnnn?



非常感谢!

解决方案

 您也可以尝试使用TCP KeepAlive功能
,导入套接字
ftp.sock.setsockopt(socket.SOL_SOCKET,socket.SO_KEEPALIVE,1)

TCP KeepAlive的支持高度依赖于平台和防火墙 - 因此无法保证,但它是为此目的而设计的,并且比添加其他线程简单得多。在哪些平台上工作?


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?

这篇关于使用线程来保持FTP控制端口活着的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆