Method Name
quit
Method Signature
quit()
Return Value
- Upon successfully closing the connection, it returns an FTP message 221 Goodbye.
- Upon failure to gracefully quit the connection, an exception is raised.
Overview
- The quit() method gracefully closes the FTP connection with the server.
- Once quit() is called, the FTP object can not be used by calling the connect() method again.
- The quit() method internally sends the QUIT command to the FTP server.
Example
# Example Python program that uses quit() method
# to close a connection with the FTP server
from ftplib import FTP
# Connect to the FTP server
ftp = FTP(host="agreatftpserver.com");
print(ftp.getwelcome());
# Login to the FTP server
reply = ftp.login();
print(reply);
# List the contents of the root directory on the FTP server
reply = ftp.dir();
print(reply);
# Gracefully quit the connection
reply = ftp.quit();
print(reply);Output
220 (vsFTPd 3.0.3)
230 Login successful.
-rw-r--r-- 1 0 0 1073741824000 Feb 19 2016 One.zip
-rw-r--r-- 1 0 0 107374182400 Feb 19 2016 Two.zip
-rw-r--r-- 1 0 0 102400 Feb 19 2016 Three.zip
None
221 Goodbye.