通过代理服务器访问FTP的Python代码

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
import urllib2
 
# Install proxy support for urllib2
proxy_info = { 'host' : 'proxy.myisp.com',
               'port' : 3128,
             }
proxy_support = urllib2.ProxyHandler({"ftp" : "http://%(host)s:%(port)d" % proxy_info})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
 
# List the content of a directory (it returns an HTML page built by the proxy)
# (You will have to parse the HTML to extract the list of files and directories.)
print urllib2.urlopen("ftp://login:password@server/directory").read()
 
# Download a file:
data = urllib2.urlopen("ftp://login:password@server/directory/myfile.zip").read()
open("myfile.zip","w+b").write(data)

标签: isp

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:Python简单调用WebService

下一篇:将时间转成几天前,几小时等的格式