On 7 Dic, 10:42, loial <[EMAIL PROTECTED]> wrote: > 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?
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 ... -- http://mail.python.org/mailman/listinfo/python-list