[Python] python ftplib can not upload and download Chinese files and folders

During the operation of ftp files using ftplib, Chinese files and folders cannot be uploaded or downloaded.

 

Check the source code of ftplib.py. The findings are as follows:

 

The encoding defaults to "latin-1"

 

Modification method:

Method 1: You can directly modify the source code of ftplib.py. Modify the 106th line of code to

encoding = "utf-8"

 

Method 2: Reset the encoding on the constructed ftp object

ftp = ftplib.FTP()
# ftp.set_debuglevel(2)
ftp.connect(host, port)
ftp.login(username, password)

#ftp.encoding='GB2312'
ftp.encoding='utf-8'

 

The above two methods can solve the failure to upload and download Chinese files and folders

Guess you like

Origin blog.csdn.net/xiezhen_zheng/article/details/103126459