[英]Some letters (ü, ä) in file name turning to gibberish after uploading to FTP in Python
I'm trying to upload image file to FTP server and filename has western European character.我正在尝试将图像文件上传到 FTP 服务器,并且文件名具有西欧字符。
file_name = 'müde_Mäuschen'
If I upload this file to FTP it changes letters.如果我将此文件上传到 FTP 它会更改字母。 File name in FTP becomes
müde_Mäuschen
. FTP 中的文件名变为
müde_Mäuschen
。
Notes:笔记:
Code:代码:
from ftplib import FTP
ftp = FTP("Login Details")
path = r'D:\ftp_test'
file_name = 'müde_Mäuschen.jpg'
ftp.storbinary(f"STOR {file_name}", open(path+'\\'+file_name, "rb"))
You need to specify the filesystem encoding of the remote system:您需要指定远程系统的文件系统编码:
ftp = FTP('Login Details', encoding='cp1252')
Otherwise filenames and directory names will be decoded with the default encoding of the local system.否则文件名和目录名将使用本地系统的默认编码进行解码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.