[Python-Dev] urllib.urlretrieve() and handling 550 errors when reading from FTP (original) (raw)

Guido van Rossum guido at python.org
Sun Jul 11 18:27:12 CEST 2004


> If you remove this, you won't be able to get a directory listing of > directories. I tried this with and without the line; with that line > in, it gives a directlry listing, without it gives an IOError (Not a > regular file): > >>>>urllib.urlretrieve("ftp://ftp.python.org/pub", "xyzzy") > > So I'd be against deleting this, unless there's a different way to get > directory listings.

Try it again but with a trailing slash on the address. With the line removed it will fetch the directory. Otherwise it errors out. The code apparently tries to get the file and when it fails with a 550 (meaning the file cannot be accessed because of permissions or lack of existence), the code then send a LIST command which lists whatever the argument is, file or directory. Unfortunately I can't think of a good way to detect the difference between a file and a directory that just doesn't have the ending slash beyond reading the output and seeing if it is a single listing for a file with the same name as the LIST request.

Why should I have to use a trailing backslash to get a directory listing? That's not in the FTP standard and probably won't work everywhere.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list