self connection storlines('stor remotenamelocalfileelselocalfile open(localpath'rb'self connection storbinary('stor remotenamelocalfilelocalfile close(def downloaddir(self)""download all files from remote site/dir per config ftp nlst(gives files listdir(gives full details ""remotefiles self connection nlst(nlst is remote listing for remotename in remotefilesif remotename in ('')continue localpath os path join(self localdirremotenameprint('downloading'remotename'to'localpath'as'end='self downloadone(remotenamelocalpathprint('done:'len(remotefiles)'files downloaded 'def uploaddir(self)""upload all files to remote site/dir per config listdir(strips dir pathany failure ends script ""localfiles os listdir(self localdirlistdir is local listing for localname in localfileslocalpath os path join(self localdirlocalnameprint('uploading'localpath'to'localname'as'end='self uploadone(localnamelocalpathlocalnameprint('done:'len(localfiles)'files uploaded 'def run(selfcleantarget=lambda:nonetransferact=lambda:none)""run complete ftp session default clean and transfer are no-ops don' delete if can' connect to server ""self connectftp(cleantarget(transferact(self connection quit(if __name__ ='__main__'ftp ftptools(xfermode 'downloadif len(sys argv xfermode sys argv pop( get+del nd arg if xfermode ='download'ftp configtransfer(ftp run(cleantarget=ftp cleanlocalstransferact=ftp downloaddirelif xfermode ='upload'ftp configtransfer(site='learning-python com'rdir='books'user='lutz'ftp run(cleantarget=ftp cleanremotestransferact=ftp uploaddirtransferring directories with ftplib