problem when getting ftp file

Discussion in 'Python' started by =?iso-8859-1?q?Francis=20Lavoie?=, Aug 17, 2004.

  1. I'm new to python and I'm not sure if I use the ftplib
    class correctly.

    I made a programm to update a pseudo-dynamic site via
    ftp. The site is a static html that include files
    update by ftp. It create 2 files, and html and a .dat
    file, which hold a easier to manipulate data.

    first of all, when I start the application, it connect
    to ftp, and get the .dat files on the ftp server to
    stay up to date. Then modification are done to the
    local file, when the application receive a update
    request, it take the local file and update it to the
    server.

    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.

    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)


    If someone can guide me where to look to find a
    solution, it will be appreciated.

    Thank you


    __________________________________________________________
    Lèche-vitrine ou lèche-écran ?
    magasinage.yahoo.ca
     
    =?iso-8859-1?q?Francis=20Lavoie?=, Aug 17, 2004
    #1
    1. Advertising

  2. > 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
     
    Robert M. Emmons, Aug 18, 2004
    #2
    1. Advertising

  3. > 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
     
    Robert M. Emmons, Aug 18, 2004
    #3
    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. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,612
    iksrazal
    Apr 25, 2004
  2. Sriram
    Replies:
    14
    Views:
    699
    Alex Hunsley
    Sep 13, 2004
  3. Vin Raja

    FTP : Time problem (net/ftp)

    Vin Raja, Jun 7, 2007, in forum: Ruby
    Replies:
    0
    Views:
    105
    Vin Raja
    Jun 7, 2007
  4. Jeff Miller
    Replies:
    0
    Views:
    527
    Jeff Miller
    Mar 26, 2009
  5. D. Buck
    Replies:
    2
    Views:
    534
    D. Buck
    Jun 29, 2004
Loading...

Share This Page