also means that the file' write method will allow for the str string passed in by retrlinesand that text will be encoded per unicode when written subtlythoughwe also explicitly use the ftp connection object' unicode encoding scheme for our text output file in openinstead of the default without this encoding optionthe script aborted with unicodeencodeerror exception for some files in my site in retrlinesthe ftp object itself reads the remote file data over socket with text-mode file wrapper and an explicit encoding scheme for decodingsince the ftp object can do no better than this encoding anyhowwe use its encoding for our output file as well by defaultftp objects use the latin scheme for decoding text fetched (as well as for encoding text sent)but this can be specialized by assigning to their encoding attribute our script' local text output file will inherit whatever encoding ftplib uses and so be compatible with the encoded text data that it produces and passes we could try to also catch unicode exceptions for files outside the unicode encoding used by the ftp objectbut exceptions leave the ftp object in an unrecoverable state in tests 've run in python alternativelywe could use wb binary mode for the local text output file and manually encode line strings with line encodeor simply use retrbinary and binary mode files in all casesbut both of these would fail to map end-lines portably--the whole point of making text distinct in this context all of this is simpler in action than in words here is the command use to download my entire book support website from my isp server account to my windows laptop pcin single stepc:\pp \internet\ftp\mirrordownloadflat py test password for lutz on home rmi netclean local directory firsty connecting deleting local -longmont-classes html deleting local -longmont-classes html deleting local -longmont-classes html deleting local about-hopl html deleting local about-lp html deleting local about-lp html deleting local about-pp-japan html lines omitted downloading -longmont-classes html to test\ -longmont-classes html as text downloading -longmont-classes html to test\ -longmont-classes html as text downloading -longmont-classes html to test\ -longmont-classes html as text downloading about-hopl html to test\about-hopl html as text downloading about-lp html to test\about-lp html as text downloading about-lp html to test\about-lp html as text downloading about-pp-japan html to test\about-pp-japan html as text client-side scripting