Welcome, Guest
Username: Password: Remember me
Components and Libraries for Networking Development, discussions, problems and suggestions
  • Page:
  • 1

TOPIC:

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6177

  • 605356316
  • 605356316's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 0
I'm writing an ftp server by using TIdFTPServer.
It shows unicode directory and filename correctly under Windows.
But It doesn't show that under linux.
I had trace indy ftp server codes for several days, such as Setp in debugging, snipper data packets by wireshark.
FINALLY! I found a solution!

In IdFTPServer, procedure TIdFTPServer.DoDataChannelOperation
about line 3686:
      if AContext.FDataChannel.FDataChannel.IOHandler.Connected then begin
        AContext.FDataChannel.FDataChannel.IOHandler.WriteLn(ASrcStrings[i], LEncoding);
change to :
      if AContext.FDataChannel.FDataChannel.IOHandler.Connected then begin
{$IFDEF WINDOWS}
        AContext.FDataChannel.FDataChannel.IOHandler.WriteLn(ASrcStrings[i], LEncoding);
{$ELSE}
        AContext.FDataChannel.FDataChannel.IOHandler.WriteLn(ASrcStrings[i], LEncoding, LEncoding);
{$ENDIF}           
It works PERFECTLY!

Please Log in or Create an account to join the conversation.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6180

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Thanks Sir
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6238

  • 605356316
  • 605356316's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 0
Fix more unicode bugs:

In IdFTPServer, find procedure TIdFTPServer.DoConnect(AContext: TIdContext);
AContext.Connection.IOHandler.DefStringEncoding := IndyTextEncoding_8Bit;
change to:
AContext.Connection.IOHandler.DefStringEncoding := IndyTextEncoding_OSDefault;

In IdCommandHandlers, find procedure TIdCommand.SendReply;
Context.Connection.IOHandler.Write(Reply.FormattedReply);
change to:
{$IFDEF WINDOWS}
  Context.Connection.IOHandler.Write(Reply.FormattedReply, false, IndyTextEncoding_UTF8, IndyTextEncoding_OSDefault);
{$ELSE}
  Context.Connection.IOHandler.Write(Reply.FormattedReply, false, IndyTextEncoding_UTF8, IndyTextEncoding_UTF8);
{$ENDIF}

And there is last bug for change directory while name contains unicode chars, wait for me updating later.

Please Log in or Create an account to join the conversation.

Last edit: by 605356316.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6239

  • 605356316
  • 605356316's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 0
In IdCommandHandlers , find procedure TIdCommandHandler.DoCommand(const AData: string; AContext: TIdContext; AUnparsedParams: string);
    LCommand.FRawLine := AData;
    LCommand.FContext := AContext;
    LCommand.FUnparsedParams := AUnparsedParams;
change to:
{$IFDEF WINDOWS}
    LCommand.FRawLine := UTF8decode(AData);
{$ELSE}
    LCommand.FRawLine := AData;
{$ENDIF}
    LCommand.FContext := AContext;
{$IFDEF WINDOWS}
    LCommand.FUnparsedParams := UTF8decode(AUnparsedParams);
{$ELSE}
    LCommand.FUnparsedParams := AUnparsedParams;
{$ENDIF}


Now, it solved all of unicode bugs for multiplatform.
I've tested on windows x86 and linux x64

Please Log in or Create an account to join the conversation.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6240

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Thanks Sir
please zip and attach all fixed files
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6243

  • 605356316
  • 605356316's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 0
Ok, here it is.
Thank you.

Please Log in or Create an account to join the conversation.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6244

  • 605356316
  • 605356316's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 0
Additional, there is part of an example of idftpserver implementation.
procedure FtpServerOnRemoveDirectory(ASender: TIdFTPServerContext;
  var VDirectory: TIdFTPFileName);
var
  tmpPath: string;
begin
  tmpPath := TrimFilename(BASE_PATH +
    PathDelim + VDirectory + PathDelim);
{$IFDEF WINDOWS}
  tmpPath := UTF8encode(tmpPath);
{$ENDIF}
  if DirectoryExistsUTF8(tmpPath) then
  begin
    RemoveDirUTF8(tmpPath);
  end;
end;             
  
procedure FtpServerOnListDirectory(ASender: TIdFTPServerContext;
  const APath: TIdFTPFileName; ADirectoryListing: TIdFTPListOutput;
  const ACmd: string; const ASwitches: string);
var
  Sr: TSearchRec;
  tmpPath: string;
begin
{$IFDEF WINDOWS}
  tmpPath := TrimFilename(BASE_PATH +
    PathDelim + SysToUTF8(APath) + PathDelim + '*');
{$ELSE}
  tmpPath := TrimFilename(BASE_PATH +
    PathDelim + APath + PathDelim + '*');
{$ENDIF}
  if FindFirstUTF8(tmpPath, faArchive or faDirectory, Sr) = 0 then
  begin
    repeat
      if (Sr.Name <> '.') and (Sr.Name <> '..') then
      begin
        with aDirectoryListing.Add do
        begin
          if (Sr.Attr and faDirectory) = faDirectory then
          begin
            ItemType := ditDirectory;
          end
          else
          begin
            ItemType := ditFile;
          end;
          FileName := Sr.Name;
          Size := Sr.Size;
          ModifiedDate := FileDateToDateTime(Sr.Time);
          // do your jobs 
        end;
      end;
    until FindNextUTF8(sr) <> 0;
  end;
  FindCloseUTF8(sr);
end;

OnChangeDirectory needn't consider converting encoding in implementation, cause there is no interaction with file system.
Other events are similar to OnRemoveDirectory, just convert encoding under Windows.

Please Log in or Create an account to join the conversation.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6245

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
Thanks Sir
we put these fixes to Lab CT ver 5.20
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6246

  • 605356316
  • 605356316's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 6
  • Thank you received: 0
my ct version is 5.0 :) , maybe there're differences between 5.1 and 5.0 in pl_indy

Please Log in or Create an account to join the conversation.

Bug Fix for TIdFTPServer List Unicode Dir/FileName 9 years 5 months ago #6249

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4512
  • Thank you received: 1101
We know that Sir
we add the proper fixed code ...
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

  • Page:
  • 1