FTP transfert

Peter Otten __peter__ at web.de
Wed Jul 14 13:15:28 CEST 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




More information about the Python-list mailing list