15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

17.6. Exercises<br />

FTP<br />

17-1. Simple FTP Client. Given the FTP examples from this chapter, write a small FTP client<br />

program that goes to your favorite Web sites and downloads the latest versions of the<br />

applications you use. This may be a script that you run every few months to make<br />

sure you're using the "latest and greatest." You should probably keep some sort of<br />

table with FTP location, login, and password for your convenience.<br />

17-2. Simple FTP Client and Pattern-Matching. Use your solution to the previous exercise as<br />

a starting point for creating another simple FTP client that either pushes or pulls a set<br />

of files from a remote host using patterns. For example, if you want to move a set of<br />

<strong>Python</strong> or PDF files from one host to another, allow users to enter "*.py" or "doc*.pdf"<br />

and only transfer those files whose names match.<br />

17-3. Smart FTP Command-Line Client. Create a command-line FTP application similar to the<br />

vanilla Unix /bin/ftp program, however, make it a "better FTP client," meaning it<br />

should have additional useful features. You can take a look at the ncFTP application as<br />

motivation. It can be found at http://ncftp.com. For example, it has the following<br />

features: history, bookmarks (saving FTP locations with log in and password),<br />

download progress, etc. You may have to implement readline functionality for history<br />

and curses for screen control.<br />

17-4. FTP and Multithreading. Create an FTP client that uses <strong>Python</strong> threads to download<br />

files. You can either upgrade your existing Smart FTP client as in the previous<br />

problem, or just write a more simple client to download files. This can be either a<br />

command-line program where you enter multiple files as arguments to the program,<br />

or a GUI where you let the user select 1+ file(s) to transfer. Extra credit: Allow<br />

patterns, i.e., *.exe. Use individual threads to download each file.<br />

17-5. FTP and GUI. Take your smart FTP client developed above and add a GUI layer on top<br />

of it to form a complete FTP application. You may choose from any of the modern<br />

<strong>Python</strong> GUI toolkits.<br />

17-6. Subclassing. Derive ftplib.FTP and make a new class FTP2 where you do not need to<br />

give "STOR filename" and "RETR filename" commands with all four (4) retr*() and<br />

stor*() methods ... you only need to pass in the filename. You may choose to either<br />

override the existing methods or create new ones with a '2' suffix, i.e., retrlines2().<br />

The file Tools/scripts/ftpmirror.py in the <strong>Python</strong> source distribution is a script that<br />

can mirror FTP sites, or portions thereof, using the ftplib module. It can be used as<br />

an extended example that applies to this module. The next five problems feature<br />

creating solutions that revolve around code like ftpmirror.py. You may use code in<br />

ftpmirror.py or implement your own solution with its code as your motivation.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!