失败报错内容如下:
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;