FTP transfert

Discussion in 'Python' started by Antoine Logean, Jul 14, 2004.

  1. Hi,

    given this code:


    from ftplib import FTP

    connection = FTP('ftp.python.org')
    connection.login()
    connection.dir()
    connection.close()

    The script write on the standart output a list of files and directories
    present on the server. Good. But how can I have this output in a string
    that I can work with ? sys.stdout is an open file object, is'nt it ?
    So if I do :

    string_out = sys.stdout.readlines()

    the script of course freeze. (what is for me logic)

    How can I solve the problem ?

    Why connection.sendcmd('ls') does not work ? the same for
    connection.sendcmd('LIST') ? 'ls' is a valid ftp command. In the RFC of
    FTP the commands are differents as the one I use every day : no get,
    mget, put, mput, ... but LIST, RETR, ... what is the difference ?

    Thanks for your help

    Antoine
     
    Antoine Logean, Jul 14, 2004
    #1
    1. Advertising

  2. Antoine Logean

    Lutz Horn Guest

    Antoine Logean <> writes:
    > connection = FTP('ftp.python.org')
    > connection.login()


    sys.stdout = open(outfilename, "w")

    > connection.dir()
    > connection.close()
     
    Lutz Horn, Jul 14, 2004
    #2
    1. Advertising

  3. Antoine Logean

    Peter Otten Guest

    Antoine Logean wrote:

    > from ftplib import FTP
    >
    > connection = FTP('ftp.python.org')
    > connection.login()
    > connection.dir()
    > connection.close()
    >
    > The script write on the standart output a list of files and directories
    > present on the server. Good. But how can I have this output in a string
    > that I can work with ? sys.stdout is an open file object, is'nt it ?
    >


    Seems like dir() accepts a callback that takes one argument, so you need not
    mess with stdout. E. g.:

    from ftplib import FTP

    connection = FTP('ftp.python.org')
    connection.login()
    lines = []
    connection.dir(lines.append)
    connection.close()

    print "\n".join(lines)

    Peter
     
    Peter Otten, Jul 14, 2004
    #3
  4. Antoine Logean <> writes:

    > connection.dir()


    Check the docs for this method; it can take an argument, a callback
    function. You can probably have this function build the representation
    you want.
     
    Tor Iver Wilhelmsen, Jul 14, 2004
    #4
  5. Antoine Logean

    Eddie Corns Guest

    Antoine Logean <> writes:

    >Hi,


    >Why connection.sendcmd('ls') does not work ? the same for
    >connection.sendcmd('LIST') ? 'ls' is a valid ftp command. In the RFC of
    >FTP the commands are differents as the one I use every day : no get,
    >mget, put, mput, ... but LIST, RETR, ... what is the difference ?


    The RFC commands constitute the protocol between FTP servers/clients and are
    specified (reasonably) exactly to get good interworking between different
    implementations. The dir, ls, get etc commands constitute the user interface
    and are modelled on what a user on that system might expect to know. The
    Python library, unusually for Python, does not do much in the way of hiding
    the protocol level commands. Perhaps there are some 3rd party addons to add a
    more user friendly level, the vaults of Parnassus
    (http://www.vex.net/parnassus/) seems to have some promising libraries.

    Eddie
     
    Eddie Corns, Jul 14, 2004
    #5
    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. Simon
    Replies:
    0
    Views:
    409
    Simon
    Jul 10, 2003
  2. =?ISO-8859-1?Q?Cl=E9ment_Goux?=

    [RMI] file transfert

    =?ISO-8859-1?Q?Cl=E9ment_Goux?=, Aug 22, 2003, in forum: Java
    Replies:
    0
    Views:
    379
    =?ISO-8859-1?Q?Cl=E9ment_Goux?=
    Aug 22, 2003
  3. someone

    FTP over SSL vs FTP over SSH

    someone, Apr 24, 2004, in forum: Java
    Replies:
    1
    Views:
    4,595
    iksrazal
    Apr 25, 2004
  4. =?iso-8859-1?q?St=E9phane_KLEIN?=

    [jakarta][FTP] progress bar transfert

    =?iso-8859-1?q?St=E9phane_KLEIN?=, Oct 5, 2004, in forum: Java
    Replies:
    1
    Views:
    528
    Paul Lutus
    Oct 5, 2004
  5. D. Buck
    Replies:
    2
    Views:
    500
    D. Buck
    Jun 29, 2004
Loading...

Share This Page