Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > FTP transfert

Reply
Thread Tools

FTP transfert

 
 
Antoine Logean
Guest
Posts: n/a
 
      07-14-2004
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

 
Reply With Quote
 
 
 
 
Lutz Horn
Guest
Posts: n/a
 
      07-14-2004
Antoine Logean <> writes:
> connection = FTP('ftp.python.org')
> connection.login()


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

> connection.dir()
> connection.close()

 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      07-14-2004
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

 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      07-14-2004
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.
 
Reply With Quote
 
Eddie Corns
Guest
Posts: n/a
 
      07-14-2004
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
 
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
[jakarta][FTP] progress bar transfert =?iso-8859-1?q?St=E9phane_KLEIN?= Java 1 10-05-2004 05:06 PM
Transfert flash to PC by using consol port Nadir Sahnoun Cisco 2 08-26-2004 11:23 AM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM
[RMI] file transfert =?ISO-8859-1?Q?Cl=E9ment_Goux?= Java 0 08-22-2003 09:01 AM
Frame + Server.Transfert Weird bug Simon ASP .Net 0 07-10-2003 11:59 AM



Advertisments