requests库不支持ftp链接。
要从FTP服务器下载文件,您可以:
import urlliburllib.urlretrieve('ftp://server/path/to/file', 'file')# if you need to pass credentials:# urllib.urlretrieve('ftp://username:password@server/path/to/file', 'file')
要么:
import shutilimport urllib2from contextlib import closingwith closing(urllib2.urlopen('ftp://server/path/to/file')) as r: with open('file', 'wb') as f: shutil.copyfileobj(r, f)
Python3:
import shutilimport urllib.request as requestfrom contextlib import closingwith closing(request.urlopen('ftp://server/path/to/file')) as r: with open('file', 'wb') as f: shutil.copyfileobj(r, f)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)