# FTP File Truncated

**URL:** <https://forum.inductiveautomation.com/t/ftp-file-truncated/1715>\
**Category:** Archived Topics\
**Created:** [April 1, 2010, 5:24pm UTC](https://forum.inductiveautomation.com/t/ftp-file-truncated/1715 "2010-04-01T17:24:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [April 1, 2010, 5:24pm UTC](https://forum.inductiveautomation.com/t/ftp-file-truncated/1715/1 "2010-04-01T17:24:59Z")

</div>

[code]from ftplib import FTP

ftp = FTP(‘[address.com](http://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.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [April 1, 2010, 8:38pm UTC](https://forum.inductiveautomation.com/t/ftp-file-truncated/1715/2 "2010-04-01T20:38:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [April 1, 2010, 8:58pm UTC](https://forum.inductiveautomation.com/t/ftp-file-truncated/1715/3 "2010-04-01T20:58:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jmehta](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jmehta](https://forum.inductiveautomation.com/u/jmehta)\
**Post date:** [July 20, 2012, 7:49pm UTC](https://forum.inductiveautomation.com/t/ftp-file-truncated/1715/4 "2012-07-20T19:49:25Z")

</div>

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.
