FTP_CREATE_MISSING_DIRS - curling operation ( added here ). I would venture to suggest that you need to do this manually using ftplib, but I would like someone to be wrong?
I would do something like the following: (untested, and need to catch ftplib.all_errors )
ftp = ... # Create connection # Change directories - create if it doesn't exist def chdir(dir): if directory_exists(dir) is False: # (or negate, whatever you prefer for readability) ftp.mkd(dir) ftp.cwd(dir) # Check if directory exists (in current location) def directory_exists(dir): filelist = [] ftp.retrlines('LIST',filelist.append) for f in filelist: if f.split()[-1] == dir and f.upper().startswith('D'): return True return False
Or you could do directory_exists as follows: (a little more difficult to read?)
# Check if directory exists (in current location) def directory_exists(dir): filelist = [] ftp.retrlines('LIST',filelist.append) return any(f.split()[-1] == dir and f.upper().startswith('D') for f in filelist)
Alex l
source share