473,769 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ftplib.nlst gives error on empty directory

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_pe rm: 550 No files found.

How can I handle this cleanly?

Dec 7 '07 #1
1 6102
On 7 Dic, 10:42, loial <jldunn2...@goo glemail.comwrot e:
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_pe rm: 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_pe rm, resp:
if str(resp) == "550 No files found":
print "Directory is empty."
else:
raise
....
Dec 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1870
by: Stephen Horne | last post by:
Just recently I decided I want to make use of my ISP freebie webspace. In order to make that easier, I'd like to be able to automatically synchronise an FTP file/folder heirarchy with one on my local hard drive. I figured this should be easily handled in Python, and broadly speaking it is, but I am having a little difficulty. You see, in order to handle the synchronise correctly, I need to be able to determine what is on the FTP server...
0
1664
by: Mikael | last post by:
Hello, I am using the ftplib.FTP.nlst() method to list the files in a directory on a FTP server. But when the directoty is empty, python raises an error: ftplib.error_perm: 550 No files found. I find this behaviour very strange. Why not simply return an empty list?
2
2953
by: Matija Papec | last post by:
I would like to reimplement ftplib "nlst" using ftplib.dir (ftp server doesn't support nlst) so I'm trying to guess how to use ftp callbacks. Any help is appreciated. tia! ============ #!/usr/bin/python # nlst vs list
0
1836
by: Peter A. Schott | last post by:
Got a strange scenario going on here in that I could have sworn this worked yesterday. I am issuing binary retrieval calls to an FTP server, writing to a file, close the file, then removing the file from the remote site. When I do this, I end up with 0 byte files. I was hoping to avoid parsing a list of remote and local files and matching them up that way because it would be easier to remove on successful retrieve. I'm including some...
10
4575
by: gabedog | last post by:
I just started maintaining an existing VB.Net FTP application that keeps directories in sync accross a firewall. The number of files and the contents of the files has grown quite large (very recently due to a new client) There are anywhere from 4,000 to 40,000 files in a directory. The file names are 20+ chars. An exception is being kicked out in the application. The exception occurs during an NLST command when there are more than the...
0
3010
by: Nico Grubert | last post by:
Hi there, I am using the ftplib library to connect to a ftp server. After I got connected, I can see a list of file in the current directory using ftp.dir() or ftp.retrlines('LIST'). But using ftp.nlst() returns an empty list which seems somehow strange to me. Here is, what I did: >>> from ftplib import FTP >>> HOST = 'my.server' >>> USER = 'myuser'
1
3551
by: Peter A. Schott | last post by:
I download a lot of 4-6 KB files and regularly run into issues with files that don't get downloaded all the way or otherwise get corrupt. I do something like: RemoteList = nlstdir() for filename in RemoteList: LocalFile = open(filename, "wb") LocalFile.write( "get file code here" ) LocalFile.close()
2
9583
by: Harlin Seritt | last post by:
Using ftplib from Python I am trying to get all files in a particular directory using ftplib and then send those same files to another ftp server. I have tried using commands like 'get *' and 'mget *' with no success. I am using the following: srcFtp = FTP(srcHost) srcFtp.login(srcUser, srcPass) srcDir = srcFtp.nlst('.')
3
3706
by: alex | last post by:
Hello, My script is trying to get a file from a remote server, every day it ftps from a directory. My code works perfect if I know the name of the file in the remote directory. ftp.retrbinary('RETR ' + filename, handleDownload) The problem is that in the future the name of the file is going to be aleatory. How can I get the file's name (only one file is in that
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.