失败报错内容如下:
Exception class EIdReplyRFCError with message
'No mapping for the Unicode character exists in the target multi-byte code page.'
网上说法,直接加在Connect;成功后加这一句就可以了。
IdFTP1.IOHandler.DefStringEncoding := IndyTextEncoding(TEncoding.UTF8);
实际上可能还是不行,因为需要服务端支持,于是搜遍内外网,找到一个方法:
// 在Connect后执行
if IdFTP1.IsExtSupported('UTF8') then
begin
// 尝试非标准UTF-8扩展,许多服务器使用这个方法...
if IdFTP1.SendCmd('OPTS UTF8 ON') <> 200 then
begin
// 尝试 draft-ietf-ftpext-utf-8-option-00.txt...
if IdFTP1.SendCmd('OPTS UTF-8 NLST') <> 200 then
Exit;
end;
IdFTP1.IOHandler.DefStringEncoding := IndyTextEncoding(TEncoding.UTF8);
end;
参考:https://codeverge.com/embarcadero.delphi.winsock/idftp-still-doesn-t-work-with-unic/1067954
另外注意:IdFTP1.Abort执行后,再次连接时先执行一下try IdFTP1.Quit; except end;

本文讲述了如何处理FTP连接时遇到的字符编码错误,包括设置IDFTP1.IOHandler.DefStringEncoding为UTF-8,以及使用'OPTS'命令与服务器协商UTF-8支持。重点介绍了使用'OPTS UTF8ON'和'OPTS UTF-8NLST'进行编码协商的步骤和注意事项。
1473

被折叠的 条评论
为什么被折叠?



