我有以下代码,可以轻松连接FTP服务器并打开zip文件。我想将该文件下载到本地系统。如何操作?
# Open the file for writing in binary mode
print 'Opening local file ' + filename
file = open(filename, 'wb')
# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)
# Clean up time
print 'Closing file ' + filename
file.close()
with
语句,它可以在完成后自动关闭文件句柄:with open(filename, "wb") as file: ftp.retrbinary("RETR " + filename, file.write)
- Lekensteynretrlines
。 - Jossie Calderon