[Delphi] IdFTP 한글 인코딩 오류



기억력 나쁜 내가 또 까먹고 indy 업데이트 할까봐 급히 메모..


IdFTP.pas 수정하면 됨.




1) TIdFTP = class(TIdExplicitTLSClient)에 프로퍼티 하나 만들고


FUTFMode: boolean;


property UTFMode : boolean read FUTFMode write FUTFMode; 




2) 소스 수정



procedure TIdFTP.List(ADest: TStrings; const ASpecifier: string = ''; ADetails: Boolean = True);      {do not localize}

var

  LDest: TMemoryStream;

  LTrans : TIdFTPTransferType;

begin

  

  if ADetails and UseMLIS and FCanUseMLS then begin

    ExtListDir(ADest, ASpecifier);

    Exit;

  end;


  LTrans := TransferType;

  if LTrans <> ftASCII then begin

    Self.TransferType := ftASCII;

  end;


  try


    LDest := TMemoryStream.Create;


    try


      InternalGet(Trim(iif(ADetails, 'LIST', 'NLST') + ' ' + ASpecifier), LDest); {do not localize}

      FreeAndNil(FDirectoryListing);

      LDest.Position := 0;


      if FUTFMode then

      begin


        {$IFDEF HAS_TEncoding}

        FListResult.LoadFromStream(LDest, IOHandler.DefStringEncoding);

        {$ELSE}

        FListResult.Text := ReadStringFromStream(LDest, -1, IOHandler.DefStringEncoding);

        {$ENDIF}


      end

      else

      begin


        {$IFDEF HAS_TEncoding}

        FListResult.LoadFromStream(LDest, TEncoding.GetEncoding(949));

        {$ELSE}

        FListResult.Text := ReadStringFromStream(LDest, -1, TEncoding.GetEncoding(949));

        {$ENDIF}


      end;



      with TIdFTPListResult(FListResult) do begin

        FDetails := ADetails;

        FUsedMLS := False;

      end;


    finally

      FreeAndNil(LDest);

    end;


    if ADest <> nil then begin

      ADest.Assign(FListResult);

    end;


    DoOnRetrievedDir;


  finally

    if LTrans <> ftASCII then begin

      TransferType := LTrans;

    end;

  end;


end;



3) 사용하기..

IdFTP.UTFMode := false;
IdFTP.SendCmd('OPTS UTF8 ON');
if IdFTP.LastCmdResult.Code = '200' then
  IdFTP.UTFMode := true;