[Pythonmac-SIG] more ftplib problems/info

Chris Barker Chris_Barker@hazmat.noaa.gov
Fri, 28 Jul 2000 13:22:51 -0700


HI all,

Well, I looked a little more into the ftplib problems I was having, and I
have some more info. I may have found a bug, but I know so little about
the FTP protocall (and TCP-IP in general) that I'm not the least but sure.

The synopsis: 
Under 1.5, ftplib appears to work, but mangles uploaded binary files
(linefeed wierdness?)

Under 1.6, ftplib won't upload a file at all, it appears to send an
incorrect PORT command.

The long story:

I ran a test script (included at the end of this post) which uploads a
binary file with debugging turned on (fill in valid data for your server,
etc), and I got the following results:

OUTPUT running under 1.5.2c1:
---------------------------
*cmd* 'CWD junk'
*put* 'CWD junk\015\012'
*get* '250 CWD command successful.\015\012'
*resp* '250 CWD command successful.'
directory changed
*cmd* 'TYPE I'
*put* 'TYPE I\015\012'
*get* '200 Type set to I.\015\012'
*resp* '200 Type set to I.'
*cmd* 'PORT 161,55,66,73,8,65'
*put* 'PORT 161,55,66,73,8,65\015\012'
*get* '200 PORT command successful.\015\012'
*resp* '200 PORT command successful.'
*cmd* 'STOU TheBarkers.JPG'
*put* 'STOU TheBarkers.JPG\015\012'
*get* '150 Opening BINARY mode data connection for TheBarkers.JPG.\015\012'
*resp* '150 Opening BINARY mode data connection for TheBarkers.JPG.'

All appears to be well, except the file got corrupted. It looks like it
might be line-ending translation, which shouldn't be happening with a
binary transfer, but it looked that way when I looked at the pre- and
post- corrupted files in a text editor.  I then did another test, and
transfered a text file in binary mode, and the mac line endings were
converted to unix line endings, which should not happen!, so that's the
problem, finding it is another matter.

This makes me wonder: Has anyone actaully used ftplib on the mac before??

Under 1.6, it didn't work at all:

OUTPUT running under 1.6a2:
---------------------------

*cmd* 'CWD junk'
*put* 'CWD junk\015\012'
*get* '250 CWD command successful.\015\012'
*resp* '250 CWD command successful.'
directory changed
*cmd* 'TYPE I'
*put* 'TYPE I\015\012'
*get* '200 Type set to I.\015\012'
*resp* '200 Type set to I.'
*cmd* 'PORT 0,0,0,0,8,58'
*put* 'PORT 0,0,0,0,8,58\015\012'
*get* '500 Illegal PORT Command\015\012'
*resp* '500 Illegal PORT Command'

Now I have found a problem: the PORT command is sending totally different
data than it did under 1.5. Looks like a bug to me. 

NOTE: I have had both of these problems with two different ftp servers:
one a Linux box  that is just a hub away form my Mac, and one a mac, that
is on the same subnet, so I don't think it's firewall or networking
problems.

By the way, when 1.6a2 exits out with this error, I have to
command+option+esc to kill it.

Thanks for any help anyone can give me.

-Chris


####  TEST SCRIPT #####
from ftplib import FTP

# set up some ftpsite data:

ftp_server = 'your server'
username = 'your username'
password = 'your password'
directory = 'your directory'

filename = 'filename to download'

server = FTP(ftp_server,username,password)
server.set_debuglevel(2)

server.cwd(directory)

file = open(filename,'r')

server.storbinary('STOU '+filename,file,1024)

file.close()

server.quit()