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.
|