As currently coded, further download status messages, including any FTP error mes-
sages, show up in the console window; here are the messages for successful downloads
as well as one that fails (with added blank lines for readability):
C:\...\PP4E\Internet\Ftp> getfilegui.py
Server Name => ftp.rmi.net
User Name? => lutz
Local Dir => test
File Name => about-pp.html
Password? => xxxxxxxx
Remote Dir =>.
Download of "about-pp.html" successful
Server Name => ftp.rmi.net
User Name? => lutz
Local Dir => C:\temp
File Name => ora-lp4e-big.jpg
Password? => xxxxxxxx
Remote Dir =>.
Download of "ora-lp4e-big.jpg" successful
Server Name => ftp.rmi.net
User Name? => lutz
Local Dir => C:\temp
File Name => ora-lp4e.jpg
Password? => xxxxxxxx
Remote Dir =>.
Download of "ora-lp4e.jpg" has failed: <class 'ftplib.error_perm'>
550 ora-lp4e.jpg: No such file or directory
Given a username and password, the downloader logs into the specified account. To
do anonymous FTP instead, leave the username and password fields blank.
Now, to illustrate the threading capabilities of this GUI, start a download of a large file,
then start another download while this one is in progress. The GUI stays active while
downloads are underway, so we simply change the input fields and press Submit again.
This second download starts and runs in parallel with the first, because each download
is run in a thread, and more than one Internet connection can be active at once. In fact,
the GUI itself stays active during downloads only because downloads are run in threads;
if they were not, even screen redraws wouldn’t happen until a download finished.
We discussed threads in Chapter 5, and their application to GUIs in Chapters 9 and
10, but this script illustrates some practical thread concerns:
- This program takes care to not do anything GUI-related in a download thread. As
we’ve learned, only the thread that makes GUIs can generally process them. - To avoid killing spawned download threads on some platforms, the GUI must also
be careful not to exit while any downloads are in progress. It keeps track of the
number of in-progress threads, and just displays a pop up if we try to kill the GUI
by pressing the Cancel button while both of these downloads are in progress.
870 | Chapter 13: Client-Side Scripting