Password? => xxxxxxxx
Remote Dir =>.
Upload of "about-pp.html" successful
Finally, we can bundle up both GUIs in a single launcher script that knows how to start
the get and put interfaces, regardless of which directory we are in when the script is
started, and independent of the platform on which it runs. Example 13-9 shows this
process.
Example 13-9. PP4E\Internet\Ftp\PyFtpGui.pyw
"""
spawn FTP get and put GUIs no matter what directory I'm run from; os.getcwd is not
necessarily the place this script lives; could also hardcode path from $PP4EHOME,
or guessLocation; could also do: [from PP4E.launchmodes import PortableLauncher,
PortableLauncher('getfilegui', '%s/getfilegui.py' % mydir)()], but need the DOS
console pop up on Windows to view status messages which describe transfers made;
"""
import os, sys
print('Running in: ', os.getcwd())
PP3E
from PP4E.Launcher import findFirst
mydir = os.path.split(findFirst(os.curdir, 'PyFtpGui.pyw'))[0]
PP4E
from PP4E.Tools.find import findlist
mydir = os.path.dirname(findlist('PyFtpGui.pyw', startdir=os.curdir)[0])
if sys.platform[:3] == 'win':
os.system('start %s\getfilegui.py' % mydir)
os.system('start %s\putfilegui.py' % mydir)
else:
os.system('python %s/getfilegui.py &' % mydir)
os.system('python %s/putfilegui.py &' % mydir)
Notice that we’re reusing the find utility from Chapter 6’s Example 6-13 again here—
this time to locate the home directory of the script in order to build command lines.
When run by launchers in the examples root directory or command lines elsewhere in
general, the current working directory may not always be this script’s container. In the
prior edition, this script used a tool in the Launcher module instead to search for its
own directory (see the examples distribution for that equivalent).
When this script is started, both the get and put GUIs appear as distinct, independently
run programs; alternatively, we might attach both forms to a single interface. We could
get much fancier than these two interfaces, of course. For instance, we could pop up
local file selection dialogs, and we could display widgets that give the status of down-
loads and uploads in progress. We could even list files available at the remote site in a
selectable listbox by requesting remote directory listings over the FTP connection. To
learn how to add features like that, though, we need to move on to the next section.
Transferring Files with ftplib | 873