[Tutor] FTP retrieve
Kent Johnson
kent37 at tds.net
Tue Mar 15 15:45:07 CET 2005
Øyvind wrote:
> I have opened an FTP connection, and use the following to download a logfile:
>
> f = open('c:///web.log','w')
> ftp.retrlines('RETR ex050202.log', f.write)
>
> I have also tried with f.writelines.
>
> It works, but not as well as I would like. All the \n's are removed. How
> can I download an exact copy, so that each line actually ends up being on
> a separate line?
Define your own callback that inserts the missing \n:
f = open('c:///web.log','w')
def cb(line):
f.write(line)
f.write('\n')
ftp.retrlines('RETR ex050202.log', cb)
Note that this callback relies on f being accessible as a global.
Kent
More information about the Tutor
mailing list