python通过代理服务器访问ftp服务

2021-11-03 13:14:26 浏览数 (1)

import urllib2

Install proxy support for urllib2

proxy_info = { 'host' : 'proxy.myisp.com', 'port' : 3128, } proxy_support = urllib2.ProxyHandler({"ftp" : % 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:").read()

Download a file:

data = urllib2.urlopen("ftp").read() open("myfile.zip","w b").write(data)</pre>

0 人点赞