Using a Callback Function - ftplib

seldan24 seldan24 at
Mon Aug 17 20:10:25 CEST 2009

On Aug 17, 1:51 pm, David <71da... at> wrote:
> Il Mon, 17 Aug 2009 10:43:33 -0700 (PDT), seldan24 ha scritto:
> > Hello,
> > I'm utterly confused by something which is most likely trivial.  I'm
> > attempting to connect to an FTP server, retrieve a list of files, and
> > store than in an array.  I.e.:
> > import ftplib
> > ftp = ftplib.FTP(server)
> > ftp.login(user, pass)
> > ftp.cwd(conf['testdir'])
> Why bother with retrlines? Use the provided higer level fuctions:
> remotefiles = []
> ftp.dir(remotefiles.append)
> or, if you prefer nlst
> remotefiles = ftp.nlst()
> regards
> david

I didn't even notice the higher level methods.  I changed the
retrieval line to:


This works great.  The result is even captured in an array.  I really
have no idea what the difference between a LIST and NLST is within
FTP.  Never delved that deep into it.  I did notice that an NLST will
return a specific FTP code if a file doesn't exist, whereas a LIST
doesn't.  So, I ended up using NLST as that'll generate an
ftplib.error_perm exception.  Based on if the job cares if a file is
not available or not (some do, some don't), I'll either exit, or
continue on with the file loop.

Anyway, thanks again, works perfectly, next time I'll try to scroll
down and read a bit more prior to posting!

More information about the Python-list mailing list