password getpass getpass('pswd?'remote/local filename remoteaddr 'ftp://lutz:% @ftp rmi net/% ;type= (passwordfilenameprint('downloading'remoteaddrthis works toourllib request urlretrieve(remoteaddrfilenameremotefile urlopen(remoteaddrlocalfile open(filename'wb'localfile write(remotefile read()localfile close(remotefile close(returns input file-like object where to store data locally note how we use binary mode output file againurllib fetches return byte stringseven for http web pages don' sweat the details of the url string used hereit is fairly complexand we'll explain its structure and that of urls in general in we'll also use urllib again in this and later to fetch web pagesformat generated url stringsand get the output of remote scripts on the web technically speakingurllib request supports variety of internet protocols (httpftpand local filesunlike ftpliburllib request is generally used for reading remote objectsnot for writing or uploading them (though the http and ftp protocols support file uploads tooas with ftplibretrievals must generally be run in threads if blocking is concern but the basic interface shown in this script is straightforward the callremotefile urllib request urlopen(remoteaddrreturns input file-like object contacts the server named in the remoteaddr url string and returns file-like object connected to its download stream (herean ftp-based socketcalling this file' read method pulls down the file' contentswhich are written to local client-side file an even simpler interfaceurllib request urlretrieve(remoteaddrfilenamealso does the work of opening local file and writing the downloaded bytes into it-things we do manually in the script as coded this comes in handy if we want to download filebut it is less useful if we want to process its data immediately either waythe end result is the samethe desired server file shows up on the client machine the output is similar to the original versionbut we don' try to automatically open this time ( 've changed the password in the url here to protect the innocent) :\pp \internet\ftpgetone-urllib py pswddownloading ftp://lutz:xxxxxx@ftp rmi net/monkeys jpg;type= :\pp \internet\ftpfc monkeys jpg test\monkeys jpg fcno differences encountered :\pp \internet\ftpstart monkeys jpg transferring files with ftplib