Delete() Method Of FTP Class In Python

Method Name:

delete

Method Signature:

delete(fileName)

Returns:

An FTP success message like, 250 File successfully deleted or an error message like, 550 permission denied.

 

Exceptions:

  • In case of permissions related failures it raises the exception error_perm and raises error_reply on other failures.

 

Overview:

  • The method delete() removes a file, as specified by the parameter filename, permanently from an FTP server.

 

Example:

# Example Python program that deletes a file

# from an FTP server

from ftplib import FTP

 

# Create an FTp instance

ftpObject = FTP();

 

# Connect to the host

ftpResponse = ftpObject.connect(host="ftpserver2connect");

print(ftpResponse);

 

# Login anonymously

ftpResponse = ftpObject.login();

print(ftpResponse);

 

# Change to a specific folder

ftpResponse = ftpObject.cwd("/uploadedfiles");

print(ftpResponse);

 

# Delete a file

ftpResponse = ftpObject.delete("ToServer.txt");

print(ftpResponse);

 

Output:

220 (vsFTPd 3.0.3)

230 Login successful.

250 Directory successfully changed.

250 File successfully deleted.


Copyright 2024 © pythontic.com