FTP delete the directory and files, and there is a file deletion prompt under the directory [550 remove directory operation failed.]

Note: if there are files in the directory, deleting the directory directly will fail, and prompt 550 remove directory operation failed

You must delete all the files in the directory before deleting the directory

FTP command line:

FTP delete directory command:

rmdir Catalog Name

FTP delete file command:

delete File Name

operation in Python:

Delete directory command:

ftp.rmd(Catalog Name)

Delete file command:

ftp.delete(File Name)

An example of deleting a directory in python3 is as follows:

from ftplib import FTP
 
ftp = FTP(host=xx, user=xx, passwd=xx)
ftp.cwd(dirname)
for i in ftp.nlst():
    print(i)
    ftp.delete(i)
ftp.cwd("..")
ftp.dir()
ftp.rmd(dirname)

Note: because there are only files in my directory, there is no directory, so you can write like above. If there is a directory in your directory, you need to delete it recursively

Similar Posts: