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

Discussion in 'Python' started by Gabriel Genellina, Jan 25, 2007.

  1. 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
     
    Gabriel Genellina, Jan 25, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. aum
    Replies:
    1
    Views:
    758
    Fredrik Lundh
    Jun 29, 2006
  2. Gabriel Genellina
    Replies:
    0
    Views:
    394
    Gabriel Genellina
    Jan 28, 2007
  3. Replies:
    2
    Views:
    505
    Giampaolo Rodola'
    Jun 6, 2008
  4. Replies:
    2
    Views:
    631
    Peter Otten
    Dec 8, 2008
  5. Jennifer

    ftplib retrlines timeout

    Jennifer, Dec 15, 2009, in forum: Python
    Replies:
    2
    Views:
    517
    Jennifer
    Dec 16, 2009
Loading...

Share This Page