Listing the files in a remote FTP server
You would like to list the files available on the official Linux kernel's FTP site, ftp.kernel.org
. You can select any other FTP site to try this recipe.
Getting ready
If you work on a production/enterprise FTP site with a user account, you need a username and password. However, in this instance, you don't need a username (and password) with the anonymous FTP server at the University of Edinburgh as you can log in anonymously.
How to do it...
We can use the ftplib
library to fetch files from our selected FTP site. A detailed documentation of this library can be found at https://docs.python.org/3/library/ftplib.html for Python 3 and at http://docs.python.org/2/library/ftplib.html for Python 2.
ftplib
is a built-in Python module, and you do not need to install it separately. Let us see how we can fetch some files with ftplib
.
Listing 5.1 gives a simple FTP connection test as follows:
#!/usr/bin/env python # Python Network Programming Cookbook, Second Edition...