# -*- coding:utf-8 -*-' Ftplib Library's read-write operation file name contains special processing in Chinese: A string received in Utf-8 format, You need to write a Unicode-encoded filename to the local file system when you save it. Test environment: server: file zilla server 0.9.50 client os: win7 ' import Ftplibfrom ftplib import ftpftp = ftplib. FTP ( ) ftp.connect (host= ' localhost ', port = 21,timeout=5) # Connect to host, default portftp.login (user= ' Honglei ', passwd= ' 111111 ' ) #names =[ ] #def mycall (line): #a = [item for item in Line.split (" ") if item!= " "] #name = a[-1]#.decode (' Utf-8 ') #size = a[-5] #names. Append (name) # Ftp.retrlines (' LIST ', Callback=mycall) # list directory contentsfilename = ' \xe8\xbf\x99\xe6\x98\xaf\xE4\xb8\xad\xe6\x96\x87.txt ' #从使用LIST获取到的ftp. Retrbinary (' retr ' + filename, open ( Filename.decode (' utf-8 '), ' WB '). Write) filename = u "Local pending Chinese file. txt" try: Ftp.storbinary (' stor ' + filename.encode (' Utf-8 '), open (filename, ' RB ')) except Ftplib.error_perm as e: pass
Python FTP client handles file names that contain Chinese