Retrieve file by FTP (using urllib)

Oleg Broytmann phd at phd.russ.ru
Fri Feb 11 11:45:33 CET 2000


Hello!

   What am I doing wrong? And how to use urllib to get files by FTP?

import urllib

try:
   fname, headers = urllib.urlretrieve("ftp://koobera.math.uic.edu/www/djb.html")
   print fname
   print headers

except Exception, msg:
   print msg
   import traceback; traceback.print_exc()


[Errno ftp error] 426 Transmission failure: not a directory
Traceback (innermost last):
  File "./xxx", line 7, in ?
    fname, headers =
urllib.urlretrieve("ftp://koobera.math.uic.edu/www/djb.html")
  File "/usr/local/lib/python1.5/urllib.py", line 66, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook)
  File "/usr/local/lib/python1.5/urllib.py", line 184, in retrieve
    fp = self.open(url)
  File "/usr/local/lib/python1.5/urllib.py", line 157, in open
    return getattr(self, name)(url)
  File "/usr/local/lib/python1.5/urllib.py", line 379, in open_ftp
    (fp, retrlen) = self.ftpcache[key].retrfile(file, type)
  File "/usr/local/lib/python1.5/urllib.py", line 582, in retrfile
    self.ftp.nlst(file)
  File "/usr/local/lib/python1.5/ftplib.py", line 397, in nlst
    self.retrlines(cmd, files.append)
  File "/usr/local/lib/python1.5/ftplib.py", line 359, in retrlines
    return self.voidresp()
  File "/usr/local/lib/python1.5/ftplib.py", line 208, in voidresp
    resp = self.getresp()
  File "/usr/local/lib/python1.5/ftplib.py", line 199, in getresp
    raise error_temp, resp
IOError: [Errno ftp error] 426 Transmission failure: not a directory


Oleg.
---- 
    Oleg Broytmann      Foundation for Effective Policies      phd at phd.russ.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list