Python FTP Commands (ftplib)
In the last article we learnt about Directory Listing of a FTP server using the Python
We learnt What a Directory is and saw how a FTP directory looks like. We used the
dir() method to produce the output which included the directory listing of the FTP server ("ftp.nluug.nl").
In this article we will learn about different FTP COMMANDS, their uses and their functionalities.
The FTP client sends commands to the FTP server, such as
ftplib library contains several methods that wrap these commands. The commands are send with the
Lets first see the Example Program and then we will see the use of the Commands and the functions used and their uses.
The example retrieves the current working directory by sending a
PWD command directly and using the
1) We send the
PWD command with the
2) This command sends a simple command string to the server and returns the response string.
parse257() is a helper method that retrieves the directory from the returned string (wdir in the example code), which also contains the status code.
1) Here we use the
pwd() method to retrieve the current working directory.
Changing The Directory:
cwd() method changes the current working directory.
The example uses the
cmd() method to change to the
This example shows how we use the
cmd() method to go from the root directory into the site folder of the FTP server "ftp.nluug.nl".
We learnt about the FTP Commands and the different methods available in the
ftplib library which are used to retrieve directory and also move from one directory to other.
In the next article, We will learn about some other methods available to create a directory, text files and other operations available in the library.