FTP File Truncated

[code]from ftplib import FTP

ftp = FTP(‘address.com’) # connect to host, default port
ftp.login(‘username’,‘password’) # user anonymous, passwd anonymous@

filename = fpmi.file.getTempFile(“gz”) #create temp file

ftp.retrbinary(‘RETR ftpfile.gz’, open(filename,‘wb’).write) #download file and write to tempfile

fpmi.file.writeFile(“C:\folder\test.gz”, fpmi.file.readFileAsBytes(filename))[/code]

Why would the file not be completely downloaded? I have checked the temp file and it is also cut off. when i try to extract the file i receive a unexpected end of archive crc failed the file is corrupt error.

I honestly don’t know - I’m not very familiar with Python’s FTP lib. Do you get any errors on the console? Perhaps you’re not closing the file stream to the temp file, and not all the bytes are being flushed out to the file?

That’s it! your a genius. I was putting the close after opening the temp file.

HI,

I am facing the same problem if you guys can help me out.
File on machine is getting created but not showing any data.
Have Test.txt file on server and want to copy the content of it to new file on machine.

Following is the code.

def getTestFile():
import os
import system
from ftplib import FTP

ftp = FTP('server name')
ftp.login('ID,'password')     

filename = system.file.getTempFile("txt") 
s=ftp.retrbinary('RETR Test.txt', open(filename,'wb').write)
print s

system.file.writeFile("C:\\TempTest\\NewTest.txt", system.file.readFileAsBytes(filename))
ftp.close()

Thank you in advance.
Need to deliver this feature urgent.