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

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I agree with other poster in that XStream is not… May 11, 2026 at 6:40 pm
  • Editorial Team
    Editorial Team added an answer Something like this works in IE 7 & FF 3… May 11, 2026 at 6:40 pm
  • Editorial Team
    Editorial Team added an answer If it were me, I'd put nicely targetable classes on… May 11, 2026 at 6:40 pm

Related Questions

I am FTPing a zip file from a remote FTP site using Python's ftplib.
I am ftp'ing files from an external server, then deleting them on the external
When I am using Bitvise Tunnelier and I spawn a new xterm window connecting
I have two computers. One computer is an old XP and the other is
I am working on localization for a asp.net application that consists of several projects.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.