ftplib LIST question

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Tue Aug 6 11:09:57 CEST 2002


On Tuesday 06 Aug 2002 4:21 am, Emile van Sebille wrote:
> Al:
> > I'm interested in parsing the output of retrlines('LIST') via a
>
> callback
>
> > routine, e.g., retrlines('LIST',mycallbackroutine()).  I'm an absolute
> > python newbie, but I'm pretty experienced with regular expressions so
> > I'm not so concerned with carving up the lines once I get them... my
> > immediate problem is what special variable (or whatever... something
> > like the perl $_ maybe?) represents each line in the context of the
> > callback routine.
>
> Call it whatever you like.  Here I used line:
> >>> def func(line): print line
>
> ...
>
> >>> ftp.retrlines('LIST', func)
>
> total 350944
> -rw-------    1 emile    emile       13800 Aug  4 13:04 .bash_history
> -rw-r--r--    1 emile    emile          24 Apr 27  2000 .bash_logout
> -rw-r--r--    1 emile    emile         262 Jul 30  2000 .bash_profile
> -rw-r--r--    1 emile    emile         124 Apr 27  2000 .bashrc
>
>
> HTH


And here is my 2 pence worth.....


def ftpparse(line):
    filename=line.split()[-1]
    print filename
    
    
import ftplib

ftp=ftplib.FTP("SERVER")
ftp.login("USERNAME", "PASSWORD")

ftp.dir("/SRC/python", ftpparse)


ftp.dir function (shorthand for ftp.retrlines('LIST', func)) calls the 
function in the second argument for each 'line' of text returned


Cheers
Martin
















More information about the Python-list mailing list