I would like to list all directories on a ftp directory and then enter each of them. The problem is that my code also list file and try to enter them as well.
- Is there a way to get a return value from the method ftp.cwd ?
- Is there a way to get only directory name in the first place, or there is a better way to do what I want.
Here is the code I am using now:
from ftplib import FTP
ftp = FTP('ftp.overtherainbow.com')
ftp.login()
for name in ftp.nlst():
print "listing: " + name
ftp.cwd(name)
ftp.retrlines('LIST')
ftp.cwd('../')
nlst
is very much alive.mlsd
can be used when the FTP server supports RFC 3659; not the case for many servers out there. – Swatch