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 8223203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:36:19+00:00 2026-06-07T14:36:19+00:00

I am trying to download a .zip file from a FTP server and I

  • 0

I am trying to download a .zip file from a FTP server and I keep getting this error:

File "C:/filename.py", line 37, in handleDownload
file.write(block)
TypeError: descriptor 'write' requires a 'file' object but received a 'str'

Here’s my code (borrowed from http://postneo.com/stories/2003/01/01/beyondTheBasicPythonFtplibExample.html):

def handleDownload(block):
    file.write(block)
    print ".",

ftp = FTP('ftp.godaddy.com') # connect to host
ftp.login("auctions") # login to the auctions directory
print ftp.retrlines("LIST")
filename = 'auction_end_tomorrow.xml.zip'
file = open(filename, 'wb')
ftp.retrbinary('RETR ' + filename, handleDownload)
file.close()
ftp.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. Editorial Team
    Editorial Team
    2026-06-07T14:36:21+00:00Added an answer on June 7, 2026 at 2:36 pm

    I can’t reproduce this myself, but I have an idea of what’s happening — I’m just not sure how it’s happening. Hopefully someone can chime in. Note that file isn’t passed through to handleDownload, and file is also the name of a builtin type. If file were left as the builtin, then you’d get exactly this error:

    >>> file
    <type 'file'>
    >>> file.write("3")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: descriptor 'write' requires a 'file' object but received a 'str'
    

    So I think some of the problem is a confusion between file, the built-in, and file, the opened file itself. (Probably using a name other than "file" is a good idea here.) Anyway, if you simply use

    ftp.retrbinary('RETR ' + filename, file.write)
    

    and ignore the handleDownload function entirely, it should work. Alternatively, if you wanted to keep the dots printing every block, you could be a little fancier, and write something like

    def handleDownloadMaker(openfile):
        def handleDownload(block):
            openfile.write(block)
            print ".",
        return handleDownload
    

    which is a function which returns a function that points at the right file. After that,

    ftp.retrbinary('RETR' + filename, handleDownloadMaker(file))
    

    should work too.

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

Sidebar

Related Questions

i'm trying to download .zip file from bluehost server to my computer. Like this
I'm trying to download a large .zip file from a web server but I
I'm trying to download a zip file (tl_2008_01001_edges.zip) from an ftp census site using
I am trying to download a zip file from an FTP location to a
I'm trying to make android download a zip file from my web server using
I am trying to write the class to download the file from server and
I'm trying to download the XLS file from this page: http://www.nordpoolspot.com/Market-data1/Elspot/Area-Prices/ALL1/Hourly/ (click on Export
I'm trying to download a zip file. It returns 0 bytes for myURL1, this
I'm trying to download a gzipped file (~390Mo) from a FTP file using java.
I'm trying to download this from GitHub, but clicking the Download ZIP link fetches

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.