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

  • SEARCH
  • Home
  • 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 3452534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:16:10+00:00 2026-05-18T09:16:10+00:00

this is my first post on here so I’m happy to be a part

  • 0

this is my first post on here so I’m happy to be a part of the community. I have a fairly mundane question to ask, but it’s been a fairly annoying problem so I’m hoping to find answers.

So I’m trying to use Python’s FTPLIB module to retrieve a binary file.

The code entered directly into the interpreter looked like this:

>>> from ftplib import FTP 

>>> ftp = FTP('xxx.xx.xx.x')  # IP of target device

>>> ftp.login()

>>> file = "foobar.xyz" # target file 

>>> ftp.retrbinary("RETR " + file, open('filez.txt', 'wb').write)

While certain functions are working (I can view all files on the device, get the welcome message from the FTP server application, and even rename files), when I try to execute the last command above, I get

    error_perm                                Traceback (most recent call last)

/Users/user_name/<ipython console> in <module>()

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.pyc in retrlines(self, cmd, callback)
    419         if callback is None: callback = print_line
    420         resp = self.sendcmd('TYPE A')
--> 421         conn = self.transfercmd(cmd)
    422         fp = conn.makefile('rb')
    423         while 1:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.pyc in transfercmd(self, cmd, rest)
    358     def transfercmd(self, cmd, rest=None):
    359         """Like ntransfercmd() but returns only the socket."""
--> 360         return self.ntransfercmd(cmd, rest)[0]
    361 
    362     def login(self, user = '', passwd = '', acct = ''):

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.pyc in ntransfercmd(self, cmd, rest)
    327             if rest is not None:
    328                 self.sendcmd("REST %s" % rest)
--> 329             resp = self.sendcmd(cmd)
    330             # Some servers apparently send a 200 reply to

    331             # a LIST or STOR command, before the 150 reply


/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.pyc in sendcmd(self, cmd)
    241         '''Send a command and return the response.'''
    242         self.putcmd(cmd)
--> 243         return self.getresp()
    244 
    245     def voidcmd(self, cmd):

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ftplib.pyc in getresp(self)
    216             raise error_temp, resp
    217         if c == '5':
--> 218             raise error_perm, resp
    219         raise error_proto, resp
    220 

error_perm: 502 Command not implemented.

I’ve looked through the ftplib source but my programming experience with these sorts of task is pretty limited, as I normally use Python for math and haven’t had to work with FTP before.

So, if anyone could give me some ideas on a solution, that would be a huge help. Alternatively, if you could suggest another solution path in a different language that would be equally helpful.

  • 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-05-18T09:16:10+00:00Added an answer on May 18, 2026 at 9:16 am

    It looks like you are logging-in anonymously (no username/password specified in ftp.login()) thus you get permission error. Try logging-in with

    ftp.login(user='foo', passwd='bar')
    

    instead.

    Edit: here is a short example of ftplib usage (simplistic, without error handling):

    #!/usr/bin/env python
    
    from ftplib import FTP
    
    HOST   = "localhost"
    UNAME  = "foo"
    PASSWD = "bar"
    DIR    = "pub"
    FILE   = "test.test"
    
    def download_cb(block):
        file.write(block)
    
    ftp = FTP(HOST)
    ftp.login(user=UNAME, passwd=PASSWD)
    ftp.cwd(DIR)
    
    file = open(FILE, "wb")
    ftp.retrbinary("RETR " + FILE, download_cb)
    file.close()
    ftp.close()
    

    Note: In case retrbinary doesn’t work, you can also try setting binary mode explicitly with ftp.sendcmd("TYPE I") before calling it. This is non-typical case, however may help with some exotic ftp servers.

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

Sidebar

Related Questions

Hello all this is my first post here i have been working in an
Well, this is my first post here and really enjoying the site. I have
this is my first post here. I'm using an existing Flash widget but would
This is my first post here. I have a problem. I need to take
This is my first post, have been a lurker for a long time, so
First post here, I have tried searching but couldn't find what I'm looking for
this is my first time to post here. I have a problem on my
This is my first post here and I wanted to get some input from
this is my first question to stackoverflow so here it goes... I use cruise
this is my first question here so I hope I can articulate it well

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.