Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:17:42+00:00 2026-05-11T06:17:42+00:00

I am FTPing a zip file from a remote FTP site using Python’s ftplib.

  • 0

I am FTPing a zip file from a remote FTP site using Python’s ftplib. I then attempt to write it to disk. The file write works, however most attempts to open the zip using WinZip or WinRar fail; both apps claim the file is corrupted. Oddly however, when right clicking and attempting to extract the file using WinRar, the file will extract.

So to be clear, the file write will work, but will not open inside the popular zip apps, but will decompress using those same apps. Note that the Python zipfile module never fails to extract the zips.

Here is the code that I’m using to get the zip file from the FTP site (please ignore the bad tabbing, that’s not the issue).

filedata = None def appender(chunk):     global filedata     filedata += chunk   def getfile(filename):   try:       ftp = None        try:           ftp = FTP(address)           ftp.login('user', 'password')        except Exception, e:           print e        command = 'RETR ' + filename        idx = filename.rfind('/')       path = filename[0:idx]       ftp.cwd(path)       fileonly = filename[idx+1:len(filename)]        ftp.retrbinary('RETR ' + filename, appender)        global filedata       data = filedata        ftp.close()        filedata = ''       return data    except Exception, e:       print e  data = getfile('/archives/myfile.zip')     file = open(pathtoNTFileShare, 'wb') file.write(data) file.close() 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:17:42+00:00Added an answer on May 11, 2026 at 6:17 am

    Pass file.write directly inside the retrbinary function instead of passing appender. This will work and it will also not use that much RAM when you are downloading a big file.

    If you’d like the data stored inside a variable though, you can also have a variable named:

    blocks = [] 

    Then pass to retrbinary instead of appender:

    blocks.append 

    Your current appender function is wrong. += will not work correctly when there is binary data because it will try to do a string append and stop at the first NULL it sees.

    As mentioned by @Lee B you can also use urllib2 or Curl. But your current code is almost correct if you make the small modifications I mentioned above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am ftp'ing files from an external server, then deleting them on the external
A third party source daily FTPs a zip file (which contains xml file) in
Someone is FTPing a file of size 10Mb to folder on a linux server.
We manage our web development using SVN. On one project, we deployed the site
On Unix, we can specify the ftp username/password in ~/.netrc file and next time
we've recently stumbled across the excellent Dispatch for ASP FTP deployment plug in. It
right now i am simply ftping everything (all of my source code included) but
I work as a freelance web dev, and up until now have been ftping
I'm only new to using SSH, but when I log in I end up
I have a shell script which I'd like to trigger from a J2EE web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.