Python网络编程:从基础到高级应用
1. urllib库的FTP资源获取
在Python中,当我们处理网络资源时,很容易只关注HTTP库而忽略了FTP资源也可以通过URL来识别。 urllib 库就是这样一个可以用于获取FTP资源的高级库。
下面是一个使用 urllib 获取FTP资源的示例代码:
#!/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:
ftp://[username[:password]@]hostname/filename
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
超级会员免费看
订阅专栏 解锁全文
13万+

被折叠的 条评论
为什么被折叠?



