Beyond the Basic Python Ftplib Example

I've been frustrated at some of the documentation and tutorials about Python.  I was looking for something beyond your typical ftplib tutorial/example/howto.  I couldn't find any, so I put together this python script that will connect to a server, print directory information, download a file using retrbinary and a callback function (which I wasn't able to find in any examples), and other various fun stuff.  There's lots more to be done, but I think that this is a slightly advanced start.  Please refer to the resources linked to below and in the file for details.

The python source is also available under terms of the GNU GPL: ftptest.py

# ftptest.py - An example application using Python's ftplib module.
# Author: Matt Croydon <
matt@ooiio.com>, referencing many sources, including:
#   Pydoc for ftplib:
http://web.pydoc.org/2.2/ftplib.html
#   ftplib module docs: http://www.python.org/doc/current/lib/module-ftplib.html
#   Python Tutorial: http://www.python.org/doc/current/tut/tut.html
# License: GNU GPL.  The software is free, don't sue me.
# This was written under Python 2.2, though it should work with Python 2.x and greater.

# Import the FTP object from ftplib
from ftplib import FTP

# This will handle the data being downloaded
# It will be explained shortly
def handleDownload(block):
    file.write(block)
    print ".",
   
# Create an instance of the FTP object
# Optionally, you could specify username and password:
# FTP('hostname', 'username', 'password')
ftp = FTP('ftp.cdrom.com')

print 'Welcome to Matt's ftplib example'
# Log in to the server
print 'Logging in.'
# You can specify username and password here if you like:
#
ftp.login('username', 'password')
# Otherwise, it defaults to Anonymous
print
ftp.login()

# This is the directory that we want to go to
directory = 'pub/simtelnet/trumpet/winsock'
# Let's change to that directory.  You kids might call these 'folders'
print 'Changing to ' + directory
ftp.cwd(directory)

# Print the contents of the directory
ftp.retrlines('LIST')

# Here's a file for us to play with.  Remember Trumpet Winsock?
filename = 'winap21f.zip'

# Open the file for writing in binary mode
print 'Opening local file ' + filename
file = open(filename, 'wb')

# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)

# Clean up time
print 'Closing file ' + filename
file.close()

print 'Closing FTP connection'
print
ftp.close()