FTP_CREATE_MISSING_DIRS es una operación curl (added here). Me arriesgaría a suponer que tienes que hacerlo manualmente con ftplib, pero me gustaría que se demuestre que está mal, ¿alguien?
me gustaría hacer algo como lo siguiente: (no probado, y necesito recuperar 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
O usted podría hacer directory_exists
como esto: (un poco más difícil de leer?)
# 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)
Gracias, aunque no era exactamente lo que estaba buscando, pero fue una buena respuesta. Gracias;) – AliBZ
No, no tiene que hacerlo manualmente. Simplemente puede llamar al método 'makedirs' en el paquete' ftputil' en su lugar. – xApple