rmd() method of class FTP in Python

The rmd() method removes a directory from the FTP server by sending the FTP command RMD. This command is sent and response is received over the control connection. Using this method, The example Python program removes a folder from an FTP server.

Ftp Updated 11 Oct 2019 1 min read

Method Name

rmd

Method Signature

rmd(dirname)

Parameter

dirname – Name of the directory

Return Value

A success message 250 Directory removed or a failure message like 550 Permission denied.

Overview

  • The method rmd() removes a directory from the FTP server.
  • The underlying FTP command is RMD.
  • To remove a file from the FTP server the method delete() can be used.

Example

python
# Example Python program to remove a directory

# from an FTP server

from ftplib import FTP

# Create an FTP instance and connect

ftpInstance = FTP(host="anftpserverhost");

print(ftpInstance.getwelcome());

# Login to the FTP server

ftpResponse = ftpInstance.login();

print(ftpResponse);

# Delete a folder

ftpResponse = ftpInstance.rmd("/toberemoved");

print(ftpResponse);

Output

Output
220 (vsFTPd 3.0.3)

230 Login successful.

250 Directory removed.