opened in text mode we also want to avoid unicode issues in python --as we also saw in strings are encoded when written in text mode and this isn' appropriate for binary data such as images text-mode file would also not allow for the bytes strings passed to write by the ftp library' retrbinary in any eventso rb is effectively required here (more on output file modes laterfinallywe call the ftp quit method to break the connection with the server and manually close the local file to force it to be complete before it is further processed (it' not impossible that parts of the file are still held in buffers before the close call)connection quit(localfile close(and that' all there is to it--all the ftpsocketand networking details are hidden behind the ftplib interface module here is this script in action on windows machineafter the downloadthe image file pops up in windows picture viewer on my laptopas captured in figure - change the server and file assignments in this script to test on your ownand be sure your pythonpath environment variable includes the pp root' containeras we're importing across directories on the examples tree herec:\pp \internet\ftppython getone py pswdconnecting downloading open file? notice how the standard python getpass getpass is used to ask for an ftp password like the input built-in functionthis call prompts for and reads line of text from the console userunlike inputgetpass does not echo typed characters on the screen at all (see the moreplus stream redirection example of for related toolsthis is handy for protecting things like passwords from potentially prying eyes be carefulthough--after issuing warningthe idle gui echoes the password anyhowthe main thing to notice is that this otherwise typical python script fetches information from an arbitrarily remote ftp site and machine given an internet linkany information published by an ftp server on the net can be fetched by and incorporated into python scripts using interfaces such as these using urllib to download files in factftp is just one way to transfer information across the netand there are more general tools in the python library to accomplish the prior script' download perhaps the most straightforward is the python urllib request modulegiven an internet address string-- urlor universal resource locator--this module opens connection to the specified server and returns file-like object ready to be read with normal file object method calls ( readreadlinetransferring files with ftplib