随笔 - 102,  文章 - 1,  评论 - 2,  阅读 - 10万

客户端使用 FtpWebRequest, 服务器是 FileZilla Server 0.9.43

上传文件时,某些文件名会导致服务器端报错,但不是每次都发生,多尝试几次后,偶尔会成功一次。
The remote server returned an error:(550) File unavailable(e.g. file not found, no access)
详细信息为 No mapping for the Unicode character exists in the target multi-byte code page

经查,FileZilla Server某个版本后仅可以使用utf-8做为文件名编码,因此客户端也应该使用utf-8

但FtpWebRequest不能显式设置编码。
启动连接时,FtpWebRequest会向服务器发送OPTS utf8 on命令。
如果服务器的响应是肯定的,FtpWebRequest将使用UTF-8。如果不是,FtpWebRequest将使用本地Windows旧版字符集。

如下内容未经确认:
测试中发现FileZilla Server响应比较慢(尤其是第一次访问登录时),可能会使FtpWebRequest误以为未收到响应,从而使用本地编码。

解决方法:
string escapedUriString = Uri.EscapeUriString(CreateUrl(fullUri));
FtpWebRequest reqFTP = (FtpWebRequest)WebRequest.Create(escapedUriString);

使用 EscapeUriString 强制编码成utf-8格式

 参考: https://www.codenong.com/19727557/

posted on   五星  阅读(1258)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示