How do you FTP ASCII if ftplib strips CR?

Gordon McMillan gmcm at hypernet.com
Tue Jun 13 16:05:32 EDT 2000


[posted and mailed]

al at servana.com wrote:

>If you look at the FTPLIB docs, it states that RETRLINES will strip 
>CR when passing the text to the RETRLINES callback.
>
>So, how do you put the CR back in if you want them?

[snip]

>ourFTP.retrlines('RETR ' + filename, open(os.path.join(localdir, 
>filename), 'w').write)

How about:

lines = []
ourFTP.retrlines('RETR ' + filename, lines.append)
open(os.path.join(localdir, filename), 
    'w').write(string.join(lines,'\n'))

or:

f = open(os.path.join(localdir, filename),'w')
wrtr = lambda ln, f=f: f.write(ln+'\n')
ourFTP.retrlines('RETR ' + filename, wrtr)

- Gordon



More information about the Python-list mailing list