[Python-bugs-list] [ python-Bugs-463177 ] ftplib broken passive mode

noreply@sourceforge.net noreply@sourceforge.net
Thu, 20 Sep 2001 05:58:33 -0700


Bugs item #463177, was opened at 2001-09-20 05:58
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=463177&group_id=5470

Category: Python Library
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: ftplib broken passive mode

Initial Comment:
(This only applies when using passive FTP)

ftplib.py assumes that the 227 response will contain
an address and port specification in the form of
(h1,h2,h3,h4,p1,p2) -- note the parentheses.  In fact,
RFC 959 does not explicitly specify the parentheses,
and gives an example conversation that includes a 227
response with no parentheses.
ftplib.py throws an exception when talking to an FTP
server that does not format the 227 response with
parentheses (not uncommon, apparently).

The parse227 function should be updated to do something
such as the following:

_parse227_re = re.compile('\d+,\d+,\d+,\d+,\d+,\d+')

def parse227(resp):
        '''Parse the '227' response for a PASV request.
        Raises error_proto if it does not contain
'(h1,h2,h3,h4,p1,p2)'
        Return ('host.addr.as.numbers', port#)
tuple.'''

        if resp[:3] <> '227':
                raise error_reply, resp
        m = _parse227_re.search(resp)
        if m is None:
                raise error_proto, resp
        numbers = string.split(m.group(), ',')
        if len(numbers) <> 6:
                raise error_proto, resp
        host = string.join(numbers[:4], '.')
        port = (string.atoi(numbers[4]) << 8) +
string.atoi(numbers[5])
        return host, port


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=463177&group_id=5470