I'm trying to delete a folder using ftplib with Python.
I've tried ftp.delete
, but it only accepts files
I've tried ftp.rmd
but that only works with empty folders.
Tried a recursion function I found online:
def remove_ftp_dir(ftp, path):
for (name, properties) in ftp.mlsd(path=path):
if name in ['.', '..']:
continue
elif properties['type'] == 'file':
ftp.delete(f"{path}/{name}")
elif properties['type'] == 'dir':
remove_ftp_dir(ftp, f"{path}/{name}")
ftp.rmd(path)
When trying to iterate over the ftp.mlsd
I get:
ftplib.error_perm: 500 Invalid command: "MLSD"