This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib.urlretrieve() with ftp error
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, jpe, vimboss
Priority: normal Keywords:

Created on 2002-11-08 11:39 by vimboss, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (3)
msg13142 - (view) Author: Bram Moolenaar (vimboss) Date: 2002-11-08 11:39
When using urllib.urlretrieve() to obtain a file
through ftp and the file is not readable the directory
listing of the file is returned.  The expected behavior
is that a "permission denied" error is generated.
The current behavior makes it impossible to detect
downloading a file failed.

To reproduce:

from urllib import urlretrieve
fname = "/pub/vim/unstable/testfile"
url = "ftp://ftp.vim.org"
resfile, h = urlretrieve(url + fname)
print "file contents: '%s'" % open(resfile).read()
print "header stuff: ", h

The result:
file contents: '-rw-------   1 506      450           
25 Nov  8 11:50 testfile
'

Using ftplib.FTP() does result in the expected error:

from ftplib import FTP
def list(s):
	print s
f = FTP("ftp.vim.org")
f.login()
f.retrbinary("RETR " + fname, list)
f.quit()

The last line of the resulting exception:
ftplib.error_perm: 550 /pub/vim/unstable/testfile:
Permission denied.
msg13143 - (view) Author: John Ehresman (jpe) * Date: 2004-07-10 20:27
Logged In: YES 
user_id=22785

This is evidently the intended behavior when a url for an
unreadable file is opened, but I think it would make more
sense to raise an exception.  To change the behavior so it
raises an exception, simply remove the test for an exception
reason starting with 550 from ftpwrapper.retrfile() in
urllib.py.
msg13144 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-07-13 00:54
Logged In: YES 
user_id=357491

So this was discussed on python-dev (see the thread at http://
mail.python.org/pipermail/python-dev/2004-July/046035.html ) and the 
conclusion was to not change the behavior.  Since that handling is the 
only way for directory listings to work when people leave off a trailing 
slash it was deemed not as nice as the current situation.

A note has been added to the "Restrictions" part of the urllib docs to 
state this behavior.
History
Date User Action Args
2022-04-10 16:05:50adminsetgithub: 37439
2002-11-08 11:39:27vimbosscreate