Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ftplib.nlst gives error on empty directory

41 views
Skip to first unread message

loial

unread,
Dec 7, 2007, 4:42:23 AM12/7/07
to
Trying to use ftplib.FTP.nlst() method to list the files in
a directory on a FTP server.

It works fine except when there are no files in the directory. Then it
gives the error

ftplib.error_perm: 550 No files found.

How can I handle this cleanly?

Giampaolo Rodola'

unread,
Dec 7, 2007, 1:25:47 PM12/7/07
to

That's the response which comes straight from the server and that
causes ftplib to raise the error_perm exception.
imho, the culprit is the server since it shouldn't return that kind of
response which clashes with the RFC-959 standard specification.
Anyway, to avoid that you could just put your code into a try/except
statement:

try:
files = ftp.nlst()
except ftplib.error_perm, resp:
if str(resp) == "550 No files found":
print "Directory is empty."
else:
raise
...

0 new messages