An example for the net

Python comes with a range of modules to support Internet protocols and data structures.

Here is a simple example that logs into a list of FTP servers and gets listings of their public directories:

#!/usr/bin/env python
# -*- python -*-
#      Name:
#   Purpose: Get a listing of /pub on some FTP servers
#    Author: Graeme Cross <>
# Copyright: Graeme Cross
#   Created: 26 June 2000
#       RCS: $Id: ftp.html,v 1.1 2000/07/09 23:18:39 mib Exp $

from ftplib import FTP

sitesList = ('', '')

for site in sitesList:
	ftp = FTP(site)
	ftp.login('anonymous', '')

# eof


  1. This script would be a lot more versatile if the sites were specified on the command line
  2. There is no error checking in this script
  3. This is an example of OOP in Python - ftplib.FTP is a class

[Previous] [Next]