title: Using Python's FTP library to retrieve files
body: <p>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.</p>
  
  <p>So I'm trying to use Python's FTPLIB module to retrieve a binary file.</p>
  
  <p>The code entered directly into the interpreter looked like this:</p>
  
  <pre><code>&gt;&gt;&gt; from ftplib import FTP 
  
  &gt;&gt;&gt; ftp = FTP('xxx.xx.xx.x')  # IP of target device
  
  &gt;&gt;&gt; ftp.login()
  
  &gt;&gt;&gt; file = "foobar.xyz" # target file 
  
  &gt;&gt;&gt; ftp.retrbinary("RETR " + file, open('filez.txt', 'wb').write)
  </code></pre>
  
  <p>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</p>
  
  <pre><code>    error_perm                                Traceback (most recent call last)
  
  /Users/user_name/&lt;ipython console&gt; in &lt;module&gt;()
  
  /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')
  --&gt; 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."""
  --&gt; 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)
  --&gt; 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)
  --&gt; 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':
  --&gt; 218             raise error_perm, resp
      219         raise error_proto, resp
      220 
  
  error_perm: 502 Command not implemented.
  </code></pre>
  
  <p>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.</p>
  
  <p>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. </p>