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

2015-01-24 0 649
通过代理服务器访问FTP的Python代码
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)

遇见资源网 python 通过代理服务器访问FTP的Python代码 http://www.ox520.com/15099.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务