python如何使用代理服务器访问ftp服务

  1. import urllib2
  2. # Install proxy support for urllib2
  3. proxy_info ={‘host’:'proxy.myisp.com’,
  4. ‘port’:3128,
  5. }
  6. proxy_support = urllib2.ProxyHandler({“ftp”:”http://%(host)s:%(port)d”% proxy_info})
  7. opener = urllib2.build_opener(proxy_support)
  8. urllib2.install_opener(opener)
  9. # List the content of a directory (it returns an HTML page built by the proxy)
  10. # (You will have to parse the HTML to extract the list of files and directories.)
  11. print urllib2.urlopen(“ftp://login:password@server/directory”).read()
  12. # Download a file:
  13. data = urllib2.urlopen(“ftp://login:password@server/directory/myfile.zip”).read()
  14. open(“myfile.zip”,”w+b”).write(data)


发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(Spamcheck Enabled)