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.request: ftplib's cwd() can do harm
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Vadim Markovtsev
Priority: normal Keywords:

Created on 2016-03-10 12:41 by Vadim Markovtsev, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (1)
msg261498 - (view) Author: Vadim Markovtsev (Vadim Markovtsev) Date: 2016-03-10 12:41
urllib/request.py, near line 2345

# Set transfer mode to ASCII!
self.ftp.voidcmd('TYPE A')
# Try a directory listing. Verify that directory exists.
if file:
    pwd = self.ftp.pwd()
    try:
        try:
            self.ftp.cwd(file)
        except ftplib.error_perm as reason:
            raise URLError('ftp error: %r' % reason) from reason
    finally:
        self.ftp.cwd(pwd)
    cmd = 'LIST ' + file
else:
    cmd = 'LIST'
conn, retrlen = self.ftp.ntransfercmd(cmd)

and near line 2314:

def init(self):
    import ftplib
    self.busy = 0
    self.ftp = ftplib.FTP()
    self.ftp.connect(self.host, self.port, self.timeout)
    self.ftp.login(self.user, self.passwd)
    _target = '/'.join(self.dirs)
    self.ftp.cwd(_target)

The fact is, one can download a file from FTP without accessing the listing of it's parent directory. Example: ftp://ftp.apnic.net/apnic/whois-data/APNIC/split/apnic.db.inetnum.gz (African whois db). So these cwd() calls prevent from successfully downloading the file. If the corresponding blocks are commented out, the file is downloaded OK.

I am not sure how to fix this, rather than totally remove cwd() stuff.
History
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70716
2016-03-10 14:37:30Vadim Markovtsevsetstatus: open -> closed
resolution: not a bug
2016-03-10 12:41:35Vadim Markovtsevcreate