print('usageftptools py ["download"upload"[localdir]'in factthis last mutation combines uploads and downloads into single filebecause they are so closely related as beforecommon code is factored into methods to avoid redundancy new herethe instance object itself becomes natural namespace for storing configuration options (they become self attributesstudy this example' code for more details of the restructuring applied againthis revision runs the same as our original site download and upload scriptssee its self-test code at the end for usage detailsand pass in command-line argument to specify "downloador "upload we haven' changed what it doeswe've refactored it for maintainability and reusec:\pp \internet\ftp\mirrorftptools py download test clean target dir firstpassword for lutz on home rmi netconnecting downloading -longmont-classes html to test\ -longmont-classes html as text lines omitted downloading relo-feb -index html to test\relo-feb -index html as text done files downloaded :\pp \internet\ftp\mirrorftptools py upload test clean target dir firstpassword for lutz on learning-python comconnecting uploading test\ -longmont-classes html to -longmont-classes html as text lines omitted uploading test\zopeoutline htm to zopeoutline htm as text done files uploaded although this file can still be run as command-line script like thisits class is really now package of ftp tools that can be mixed into other programs and reused by wrapping its code in classit can be easily customized by redefining its methods--its configuration callssuch as getlocaldirfor examplemay be redefined in subclasses for custom scenarios perhaps most importantlyusing classes optimizes code reusability clients of this file can both upload and download directories by simply subclassing or embedding an instance of this class and calling its methods to see one example of howlet' move on to the next section transferring directory trees with ftplib perhaps the biggest limitation of the website download and upload scripts we just met is that they assume the site directory is flat (hence their namesthat isthe preceding scripts transfer simple files onlyand none of them handle nested subdirectories within the web directory to be transferred client-side scripting