FTP 文件名编码
你好 我使用扭曲库连接到 FTP 服务器,但文件名编码有问题。 我收到“Illusion-N\xf3z.txt”,因此它不是 unicode。是否有任何 FTP 命令可以强制指定编码? 提前致谢! MK
Hi
I use twisted library to connect to FTP server but I have problem with filename encoding.
I receive 'Illusion-N\xf3z.txt' so its not unicode. Is there any FTP command to force specific encoding?
Thanks in advance!
MK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两种可能性:
FEAT
命令的结果以查看UTF8
是否存在(但可能不存在,因为示例字节不是有效的 UTF-8)。如果是,则使用 UTF-8 解码字节。Twisted 的 FTP 客户端不会执行任何与 unicode 相关的操作,因为它只是实现基本的 FTP RFC。
There are two possibilities:
FEAT
command to see ifUTF8
is there (but it probably isn't, since the example bytes are not valid UTF-8). If it is, decode the bytes using UTF-8.Twisted's FTP client won't do anything unicode-related for it, since it just implements the basic FTP RFC.
FTP 忽略编码;只要文件名不包含
'\0'
(空字符)和'/'
(斜杠)分隔目录,它就乐意接受任何内容。对文件名进行自己的解码和编码。您的示例中使用的编码很可能是“cp1252”,即“Windows Western”或类似的编码。
在您的情况下,当您收到“Illusion-N\xf3z.txt”时,请通过
'Illusion-N\xf3z.txt'.decode('cp1252')
将其转换为 Unicode。FTP ignores encodings; as long as a filename does not contain a
'\0'
(null character) and'/'
(slash) separates directories, it happily accepts anything.Do your own decoding and encoding of the filenames. It is quite probable that the encoding used in your example is "cp1252", which is the “Windows Western” or something like that.
In your case, when you receive 'Illusion-N\xf3z.txt', convert it to Unicode by
'Illusion-N\xf3z.txt'.decode('cp1252')
.