我试图使用Python的ftplib读取文件而不编写它们.大致相当于:
def get_page(url):
try:
return urllib.urlopen(url).read()
except:
return ""
Run Code Online (Sandbox Code Playgroud)
但使用FTP.
我试过了:
def get_page(path):
try:
ftp = FTP('ftp.site.com', 'anonymous', 'passwd')
return ftp.retrbinary('RETR '+path, open('page').read())
except:
return ''
Run Code Online (Sandbox Code Playgroud)
但这不起作用.文档中的唯一示例涉及使用该ftp.retrbinary('RETR README', open('README', 'wb').write)格式编写文件.是否可以在不先写入的情况下读取ftp文件?