def connectftp(cf)print('connecting 'connection ftplib ftp(cf remotesiteconnection login(cf remoteusercf remotepassconnection cwd(cf remotedirif cf nonpassiveconnection set_pasv(falsereturn connection not compressed connect to ftp site log in as user/password cd to directory to xfer force active mode ftp most servers do passive def cleanlocals(cf)""try to delete all locals files first to remove garbage ""if cf cleanallfor localname in os listdir(cf localdir)local dirlisting trylocal file delete print('deleting local'localnameos remove(os path join(cf localdirlocalname)exceptprint('cannot delete local'localnamedef downloadall(cfconnection)""download all files from remote site/dir per cf config ftp nlst(gives files listdir(gives full details ""remotefiles connection nlst(nlst is remote listing for remotename in remotefilesif remotename in ('')continue localpath os path join(cf localdirremotenameprint('downloading'remotename'to'localpath'as'end='if istextkind(remotename)use text mode xfer localfile open(localpath' 'encoding=connection encodingdef callback(line)localfile write(line '\ 'connection retrlines('retr remotenamecallbackelseuse binary mode xfer localfile open(localpath'wb'connection retrbinary('retr remotenamelocalfile writelocalfile close(connection quit(print('done:'len(remotefiles)'files downloaded 'if __name__ ='__main__'cf configtransfer(conn connectftp(cfcleanlocals(cfdownloadall(cfconndon' delete if can' connect compare this version with the original this scriptand every other in this sectionruns the same as the original flat download and upload programs although we haven' client-side scripting