Rmd() Method Of Class FTP In Python

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:

# 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:

220 (vsFTPd 3.0.3)

230 Login successful.

250 Directory removed.


Copyright 2022 © pythontic.com