problem when getting ftp file

Robert M. Emmons RobMEmmons at cs.com
Tue Aug 17 20:31:27 EDT 2004


> The update work perfectly, but the part I get the file
> from ftp cause me some trouble. The client app is run
> on windows. To create the file and to read it, I use
> open("myfile.dat").write and readlines, there's no
> problem, but when I get a new file from ftp, the
> return line disapear and readlines take the all the
> file as one line.

It sounds like your loosing new lines because of the way your using text 
and binary file options.  When you open a file with python you can open 
it as "r" or "rb" mode in the open statement.  For writing it's "w" or 
"wb".  With the "b" (binary) data is transfered unchanged.  Without it, 
python will translate newlines \n to \r\n on output and then translate 
\r\n to \n on input.  This is because different systems use different 
textual line terminators -- linux=\n, windows=\r\n, and mac=\r.

I think FTP also has text and binary transfer modes -- too.  As a 
result, you need to choose all of these combinations carefully.

 > To write the new file in ftp I use :
 > storlines("STOR", open("myfile.dat").read)
 > And to get it I use :
 > retrlines("RETR", open("myfile.dat").write)

By the way, the write above looks wrong to me.  Don't you need to use 
open("myfile.dat","w")?

Rob






More information about the Python-list mailing list