Python网络编程:从基础到高级应用
1. 利用urllib进行FTP资源获取
在Python中,我们可以使用 urllib 库来获取FTP资源。 urllib 是Python标准库中的高级库,很多人可能只将其与HTTP库联系起来,而忽略了它也能用于处理FTP资源。
以下是使用 urllib 的示例代码:
#!/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.a
超级会员免费看
订阅专栏 解锁全文
13万+

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



