How to make Python check if ftp directory exists?

Posted by Phil on Stack Overflow See other posts from Stack Overflow or by Phil
Published on 2009-07-08T13:51:56Z Indexed on 2013/11/13 9:54 UTC
Read the original article Hit count: 311

Filed under:
|

I'm using this script to connect to sample ftp server and list available directories:

from ftplib import FTP
ftp = FTP('ftp.cwi.nl')   # connect to host, default port (some example server, i'll use other one)
ftp.login()               # user anonymous, passwd anonymous@
ftp.retrlines('LIST')     # list directory contents
ftp.quit()

How do I use ftp.retrlines('LIST') output to check if directory (for example public_html) exists, if it exists cd to it and then execute some other code and exit; if not execute code right away and exit?

© Stack Overflow or respective owner

Related posts about python

Related posts about ftp