its code is now set of tools that can be imported and reused in other programs the refactored upload program in example - for instanceis now noticeably simplerand the code it shares with the download script only needs to be changed in one place if it ever requires improvement example - pp \internet\ftp\mirror\uploadflat_modular py #!/bin/env python ""#############################################################################use ftp to upload all files from local dir to remote site/directorythis version reuses downloader' functionsto avoid code redundancy#############################################################################""import os from downloadflat_modular import configtransferconnectftpistextkind def cleanremotes(cfconnection)""try to delete all remote files first to remove garbage ""if cf cleanallfor remotename in connection nlst()remote dir listing tryremote file delete print('deleting remote'remotenameskips and exc connection delete(remotenameexceptprint('cannot delete remote'remotenamedef uploadall(cfconnection)""upload all files to remote site/dir per cf config listdir(strips dir pathany failure ends script ""localfiles os listdir(cf localdirlistdir is local listing for localname in localfileslocalpath os path join(cf localdirlocalnameprint('uploading'localpath'to'localname'as'end='if istextkind(localname)use text mode xfer localfile open(localpath'rb'connection storlines('stor localnamelocalfileelseuse binary mode xfer localfile open(localpath'rb'connection storbinary('stor localnamelocalfilelocalfile close(connection quit(print('done:'len(localfiles)'files uploaded 'if __name__ ='__main__'cf configtransfer(site='learning-python com'rdir='books'user='lutz'transferring directories with ftplib