user=('lutz'getpass('pswd?'))refetch=truerest is the same if input('open file?'in [' '' ']from pp system media playfile import playfile playfile(filenamebesides having much smaller line countthe meat of this script has been split off into file for reuse elsewhere if you ever need to download file againsimply import an existing function instead of copying code with cut-and-paste editing changes in download operations would need to be made in only one filenot everywhere we've copied boilerplate codegetfile getfile could even be changed to use urllib rather than ftplib without affecting any of its clients it' good engineering download utility so just how would we go about writing such an ftp interface wrapper (he asksrhetorically)given the ftplib library modulewrapping downloads of particular file in particular directory is straightforward connected ftp objects support two download methodsretrbinary this method downloads the requested file in binary modesending its bytes in chunks to supplied functionwithout line-feed mapping typicallythe supplied function is write method of an open local file objectsuch that the bytes are placed in the local file on the client retrlines this method downloads the requested file in ascii text modesending each line of text to supplied function with all end-of-line characters stripped typicallythe supplied function adds \ newline (mapped appropriately for the client machine)and writes the line to local file we will meet the retrlines method in later examplethe getfile utility module in example - always transfers in binary mode with retrbinary that isfiles are downloaded exactly as they were on the serverbyte for bytewith the server' line-feed conventions in text files (you may need to convert line feeds after downloads if they look odd in your text editor--see your editor or system shell commands for pointersor write python script that opens and writes the text as neededexample - pp \internet\ftp\getfile py #!/usr/local/bin/python ""fetch an arbitrary file by ftp anonymous ftp unless you pass user=(namepswdtuple self-test ftps test file and site ""transferring files with ftplib