免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3113 | 回复: 0

ftp 获取文件 [复制链接]

论坛徽章:
0
发表于 2009-11-03 20:09 |显示全部楼层
#!/usr/bin/env python
"""
url retriever
Usage:
   
url_retrieve_urllib.py URL FILENAME
URL:
If the URL is an FTP URL the format should be:
[url=ftp://[username[:password]@]hostname/filename]ftp://[username[:password]@]hostname/filename[/url]
If you want to use absolute paths to the file to download,
you should make the URL look something like this:
ftp://user:password@host/%2Fpath/to/myfile.txt
Notice the '%2F' at the beginning of the path to the file.
FILENAME:
absolute or relative path to the filename to save downloaded file as
"""
import urllib
import sys
if '-h' in sys.argv or '--help' in sys.argv:
    print __doc__
    sys.exit(1)
if not len(sys.argv) == 3:
    print 'URL and FILENAME are mandatory'
    print __doc__
    sys.exit(1)
url = sys.argv[1]
filename = sys.argv[2]
urllib.urlretrieve(url, filename)


将上面的命名为
ftp.py

比如放到c盘下
cmd-->cd ../.. >ftp.py
ftp://root:123456@192.168.1.2
a.txt
获取192.168.1.2主机上/root下面的a.txt,因为默认目录就是/root。

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103983/showart_2085663.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP