我正在尝试从 FTP 服务器下载 .zip 文件,但我不断收到此错误:
File "C:/filename.py", line 37, in handleDownload
file.write(block)
TypeError: descriptor 'write' requires a 'file' object but received a 'str'
这是我的代码(借自http://postneo.com/stories/2003/01/01/beyondTheBasicPythonFtplibExample.html):
def handleDownload(block):
file.write(block)
print ".",
ftp = FTP('ftp.godaddy.com') # connect to host
ftp.login("auctions") # login to the auctions directory
print ftp.retrlines("LIST")
filename = 'auction_end_tomorrow.xml.zip'
file = open(filename, 'wb')
ftp.retrbinary('RETR ' + filename, handleDownload)
file.close()
ftp.close()