【发布时间】:2014-09-09 12:11:15
【问题描述】:
我正在尝试使用 python 从 ftp 站点检索一个 zip 文件夹并将它们保存到我的本地计算机(理想情况下,我想指定它们在我的 C 上的保存位置:)。
下面的代码连接到 FTP 站点,然后 *在 PyScripter 窗口中发生了一些看起来像大约 1000 行的随机字符...但实际上没有任何内容下载到我的硬盘驱动器。
有什么建议吗?
import ftplib
import sys
def gettext(ftp, filename, outfile=None):
# fetch a text file
if outfile is None:
outfile = sys.stdout
# use a lambda to add newlines to the lines read from the server
ftp.retrlines("RETR " + filename, lambda s, w=outfile.write: w(s+"\n"))
def getbinary(ftp, filename, outfile=None):
# fetch a binary file
if outfile is None:
outfile = sys.stdout
ftp.retrbinary("RETR " + filename, outfile.write)
ftp = ftplib.FTP("FTP IP Address")
ftp.login("username", "password")
ftp.cwd("/MCPA")
#gettext(ftp, "subbdy.zip")
getbinary(ftp, "subbdy.zip")
【问题讨论】: