前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python通过代理服务器访问ftp服务

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

原创
作者头像
用户7365393
修改2021-11-01 13:58:00
2K0
修改2021-11-01 13:58:00
举报
代码语言:javascript
复制
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)</pre> 

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档