[Python-bugs-list] [ python-Bugs-441712 ] Exception using passive ftp with OS 390

noreply@sourceforge.net noreply@sourceforge.net
Mon, 16 Jul 2001 08:11:09 -0700


Bugs item #441712, was opened at 2001-07-16 08:11
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=441712&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Henrik Weber (hweber)
Assigned to: Nobody/Anonymous (nobody)
Summary: Exception using passive ftp with OS 390

Initial Comment:
Machines equipped with OS 390 (IBM mainframes) 
sometimes use a product called TCPaccess, built by a 
company called Interlink. Among other things this 
includes a FTP server.

Starting with Python 2.1 ftplib tries to switch to 
passive mode when one uses a command like dir. The 
syntax of the response of the TCPacess FTP server is 
not what ftplib expects, so an exception is raised. 
This is the traceback:

Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "c:\programme\python21\lib\ftplib.py", line 
420, in dir
    self.retrlines(cmd, func)
  File "c:\programme\python21\lib\ftplib.py", line 
352, in retrlines
    conn = self.transfercmd(cmd)
  File "c:\programme\python21\lib\ftplib.py", line 
296, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "c:\programme\python21\lib\ftplib.py", line 
273, in ntransfercmd
    host, port = parse227(self.sendcmd('PASV'))
  File "c:\programme\python21\lib\ftplib.py", line 
514, in parse227
    if left < 0: raise error_proto, resp
error_proto: 227 Entering passive mode    
25,64,88,88,16,7


Function parse227, which raises the exception, expects 
the address and port in brackets, which the server 
doesn't deliver in this case. This causes the function 
to raise the exception shown. Passive mode is not the 
default in versions prior to Python 2.1 so the problem 
didn't show before, although versions prior to 2.1 
would have reacted the same way when trying to use 
passive mode. Although the fault is on the side of the 
server the function can easily be changed to accept 
this kind of syntax as well, which would make life 
easier for people who are trying to interface to that 
kind of machine:

diff -u ftplib.py c:/tmp/ftplib.py
--- ftplib.py   Sun Apr  8 23:24:52 2001
+++ c:/tmp/ftplib.py    Mon Jul 16 14:16:14 2001
 import os
 import sys
 import string
+import re
 
 # Import SOCKS module if it exists, else standard 
socket module socket
 try:
@@ -510,12 +511,10 @@
     if resp[:3] != '227':
         raise error_reply, resp
-    left = resp.find('(')
-    if left < 0: raise error_proto, resp
-    right = resp.find(')', left + 1)
-    if right < 0:
-        raise error_proto, resp # should 
contain '(h1,h2,h3,h4,p1,p2)'
-    numbers = resp[left+1:right].split(',')
+    tuple = re.search(r'\d{1,3},\d{1,3},\d{1,3},\d
{1,3},\d{1,3},\d{1,3}', resp).group()
+    if not tuple:
+        raise error_proto, resp
+    numbers = tuple.split(',')
     if len(numbers) != 6:
         raise error_proto, resp
     host = '.'.join(numbers[:4])


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

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