[Patches] urllib NLST patch

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Fri, 11 Feb 2000 16:02:49 +0100


from the newsgroup:

Oleg Broytmann <phd@phd.russ.ru> wrote:
> What am I doing wrong? And how to use urllib to get files by FTP?
>
> fname, headers =3D =
urllib.urlretrieve("ftp://koobera.math.uic.edu/www/djb.html")
>
> IOError: [Errno ftp error] 426 Transmission failure: not a directory

background: urllib issues an NLST command to make sure
the file exists, before starting the download.  however,
RFC959 doesn't necessarily allow this:

    [NLST] causes a directory listing to be sent from
    server to user site.  The pathname should specify a
    directory or other system-specific file group descriptor;
    a null argument implies the current directory.

most FTP servers seem to treat NLST commands as
an ordinary "ls -l", but this one doesn't.

I'm pretty sure the only reasonable solution is to remove
the offending code from urllib...

-- end of posting

and here's a patch that does exactly that.  cannot see
any problems with it, but on the other hand, I'm pretty
sure the NLST call was added for a reason.

please discuss before applying.

*** urllib.py.bak Wed Feb 02 00:36:53 2000
--- urllib.py Fri Feb 11 15:53:51 2000
***************
*** 643,655 ****
              self.ftp.voidcmd(cmd)
          conn =3D None
          if file and not isdir:
-             # Use nlst to see if the file exists at all
-             try:
-                 self.ftp.nlst(file)
-             except ftplib.error_perm, reason:
-                 raise IOError, ('ftp error', reason), =
sys.exc_info()[2]
-             # Restore the transfer mode!
-             self.ftp.voidcmd(cmd)
              # Try to retrieve as a file
              try:
                  cmd =3D 'RETR ' + file
--- 643,648 ----

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.

</F>