Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: ftplib and retrbinary or retrlines (losing newlinecharacters in my log files)

Reply
Thread Tools

Re: ftplib and retrbinary or retrlines (losing newlinecharacters in my log files)

 
 
Gabriel Genellina
Guest
Posts: n/a
 
      01-25-2007
At Thursday 25/1/2007 03:05, aus stuff wrote:

>Hi am successfully downloading my text files and writing them to
>local files with either
>
><ftp://ftp.retrlines('RETR>ftp.retrlines('RETR ' + fl, fileObj.write)"
>
><ftp://ftp.retrbinary('retr/>ftp.retrbinary('RETR ' + fl, fileObj.write)
>
>However all my recieved (log) files have lost thier newline characters?


Both methods are different. From the docs for retrlines: "Retrieve a
file or directory listing in ASCII transfer mode (...) The callback
function is called for each line, with the trailing CRLF stripped.".
The callback should be responsible of writting the missing '\n' then
(fileObj should have been opened in text mode):

<ftp://ftp.retrlines('RETR>ftp.retrlines('RETR ' + fl, lambda line:
fileObj.write('%s\n' % line))

Using retrbinary() you get the file in pieces, thay you should write
in binary mode (just as the original code). The resulting file should
be identical to the original file on the server. Line endings may be
different on both platforms (some editors may allow to convert
between \n, \r\n, \r...). That's why for a log file the ASCII
transfer mode is better.


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ftplib retrlines timeout Jennifer Python 2 12-16-2009 10:01 PM
ftp retrlines with re... isabellknauer@googlemail.com Python 2 12-08-2008 10:40 AM
Partial download with ftplib and retrbinary fepeacock@googlemail.com Python 2 06-06-2008 02:23 PM
Re: ftplib and retrbinary or retrlines (losing newlinecharacters in my log files) Gabriel Genellina Python 0 01-28-2007 11:23 PM
ftplib.FTP.retrbinary() hangs on completion aum Python 1 06-29-2006 11:16 AM



Advertisments