faqts : Computers : Programming : Languages : Python : Modules : ftplib

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 3 people (67%) answered Yes
Recently 2 of 3 people (67%) answered Yes

Entry

How do I store the result of retrlines into a variable?

Mar 11th, 2007 23:43
Utkarsh Upadhyay, Eric Wood,


ftplib.FTP.retrlines(cmd,callback=None) takes two arguments, as the help
says.
The default callback is the print_line(), which prints the results.
You can call your own function here which takes an argument and appends
the entry to an existing list.

Sample code:

ftp=ftplib.FTP('the.host.name')
ftp.login('username','passwd')
lines=[]
ftp.retrlines('RETR filename.txt',lambda x:lines.append(x))