在 Python ftplib 中列出名称中包含 UTF-8 字符的文件

List files with UTF-8 characters in the name in Python ftplib

我需要将文件从 FTP 服务器镜像到本地机器,但是有些 files/directories 上面有特殊字符,例如:

print(ftp.nlst())
>>{'Mariana', 'Marina', 'MartÃ\xadn', 'MatÃ\xadas'}

假设文件名采用 UTF-8 编码,在 Python 3 中,应该这样做:

ftp.encoding = "UTF-8"
print(ftp.nlst())