Python ftplib没有完全下载

Python ftplib没有完全下载,python,ftplib,Python,Ftplib,我使用PythonFTPLIB从构建ftp服务器下载构建。文件大小约为1.5-1.6 GB。 我使用批处理文件来运行程序。这样更容易安排下载。 问题是,下载的文件似乎不起作用。它们抛出一个兼容性错误(windows)。如果我使用FileZilla下载这些文件,这些文件就可以正常工作。 而且,源文件和下载的文件之间有几百B的差异。发生了什么事 import ftplib, sys, os ftp = ftplib.FTP("<server_name") try: ftp.login

我使用PythonFTPLIB从构建ftp服务器下载构建。文件大小约为1.5-1.6 GB。 我使用批处理文件来运行程序。这样更容易安排下载。 问题是,下载的文件似乎不起作用。它们抛出一个兼容性错误(windows)。如果我使用FileZilla下载这些文件,这些文件就可以正常工作。 而且,源文件和下载的文件之间有几百B的差异。发生了什么事

import ftplib, sys, os

ftp = ftplib.FTP("<server_name")
try:
    ftp.login(user= "<user>", passwd = "<password>")
except:
    sys.stderr.write('Could not login.')

data=[]
ftp.dir(data.append)
builds=[]

trg=0           
trg_bld=""
for i in data:
    if len(i.split(" "))>12:
        if len(i.split(" ")[12].split("_"))>2:
    #this line is to find the version on the server
            if (i.split(" ")[12].split("_")[1]== "3.1.0"):
                if int(i.split(" ")[12].split("_")[2])>trg:
                    trg_bld = i.split(" ")[12]

trg_file = trg_bld
print trg_file
if os.path.isfile(trg_file):
    sys.stderr.write('File already exists.')
    sys.exit(1)
f= open(trg_file, "w")
ftp.retrbinary('RETR '+trg_bld, f.write)
f.close()
ftp.close()
sys.stdout.write("File download successful.")
导入ftplib、系统、操作系统
ftp=ftplib.ftp(“
f=open(trg\u file,“w”)
->
f=open(trg\u file,“wb”)

如果没有
b
标志,Python会认为您正在编写ASCII,并且它正在更改行尾(因此大小差异和断开的二进制文件)。

f=open(trg_文件,“w”)
->
f=open(trg_文件,“wb”)

如果没有
b
标志,Python认为您正在编写ASCII,并且它正在更改行尾(因此大小差异和中断的二进制文件)