Python FTP shows how to work with FTP in Python using
ftplib library. We are going to connect to FTP servers, list directories, download and upload files.
What is FTP ?:
File Transfer Protocol (FTP) is a standard network protocol used for transferring of computer files between a client and server on a computer network. Clients and servers communicate with a set of FTP commands, such as DELE, RETR, or CWD. Many servers provide FTP services with an anonymous FTP access. It can be used without authentication but that will be less secure. Most common web browsers can retrieve files hosted on FTP servers.
ftplib is a module that implements the client side of the FTP protocol. It contains an FTP client class and some helper functions.
ftplib library is already included in the python package. We need not install it rather just import it in our program as given below.
Python FTP class:
ftplib.FTP() creates a new instance of the FTP class. When host is given, a connection to the host is made with the
with command will automatically close the connection to the server.
getwelcome() returns the welcome message sent by the server in reply to the initial connection. This message may contain some helpful information for the user.
The above example creates a connection to the nluug FTP server, which has an anonymous account and returns its welcome message.
quit()method is used to disconnect from the FTP server. It returns a simple Goodbye message.
In this way we use the FTP library of Python to perform different operations. We will see about more methods and their uses in the upcoming articles.