-1

当我使用此代码从 FTP 服务器下载 zip 文件时,它返回已损坏。有谁知道为什么?

from ftplib import FTP
import getpass

user = raw_input('Username: ')
password = getpass.getpass()
host = raw_input('Host:')
ftp = FTP(host,user,password)
ftp.retrlines('LIST')
f_file = raw_input('What is the name of the file you would like to download? ')
print 'Opening local file...'
l_file = open(f_file, 'w')
print "Getting", f_file
ftp.retrbinary('RETR ' + f_file, l_file.write)
print "Closing", f_file
l_file.close()
print 'Closing FTP connection'
ftp.close()
4

1 回答 1

3

这可能是因为您正在以 ASCII 模式而不是二进制模式编写本地副本,从而将所有0A字节更改为0D0A(LF 到 CRLF),从而损坏了二进制文件。

再试一次l_file = open(f_file, 'wb')

于 2011-10-22T15:06:22.133 回答