ADD: FTP partial UTF-8 support

FIX: Bug [0000761] Error in list of file names that return plugin
This commit is contained in:
Alexander Koblov 2015-05-03 08:48:22 +00:00
commit 48d8dfb838
2 changed files with 22 additions and 13 deletions

View file

@ -75,9 +75,10 @@ type
private
FUnicode: Boolean;
protected
FClientToServer,
FServerToClient: TConvertEncoding;
function Connect: Boolean; override;
public
ClientToServer,
ServerToClient: TConvertEncoding;
public
constructor Create; reintroduce;
function Login: Boolean; override;
@ -160,8 +161,8 @@ constructor TFTPSendEx.Create;
begin
inherited Create;
FDirectFile:= True;
FClientToServer:= @Dummy;
FServerToClient:= @Dummy;
ClientToServer:= @Dummy;
ServerToClient:= @Dummy;
end;
function TFTPSendEx.Login: Boolean;
@ -179,8 +180,8 @@ begin
if FUnicode then
begin
FTPCommand('OPTS UTF8 ON');
FClientToServer:= @AnsiToUtf8;
FServerToClient:= @Utf8ToAnsi;
ClientToServer:= @AnsiToUtf8;
ServerToClient:= @Utf8ToAnsi;
Exit;
end;
end;
@ -206,8 +207,8 @@ begin
SendStream.PluginNumber:= PluginNumber;
SendStream.ProgressProc:= ProgressProc;
SendStream.RemoteName:= PAnsiChar(FileName);
SendStream.LocalName:= PAnsiChar(FDirectFileName);
SendStream.RemoteName:= PAnsiChar(ServerToClient(FileName));
try
if not DataSocket then Exit;
@ -254,8 +255,8 @@ begin
RetrStream.FileSize := FileSize;
RetrStream.PluginNumber := PluginNumber;
RetrStream.ProgressProc := ProgressProc;
RetrStream.RemoteName := PAnsiChar(FileName);
RetrStream.LocalName := PAnsiChar(FDirectFileName);
RetrStream.RemoteName := PAnsiChar(ServerToClient(FileName));
try
FTPCommand('TYPE I');
@ -277,9 +278,10 @@ end;
procedure TFTPSendEx.FTPStatus(Sender: TObject; Response: Boolean;
const Value: String);
begin
LogProc(PluginNumber, msgtype_details, PAnsiChar(Value));
if FSock.LastError <> 0 then
LogProc(PluginNumber, msgtype_details, PAnsiChar(ServerToClient(Value)));
if FSock.LastError <> 0 then begin
LogProc(PluginNumber, msgtype_details, PAnsiChar('Network error: ' + FSock.LastErrorDesc));
end;
end;
function TFTPSendEx.NetworkError: Boolean;

View file

@ -116,6 +116,7 @@ type
TListRec = record
Path: AnsiString;
Index: Integer;
FtpSend: TFTPSendEx;
FtpList: TFTPListEx;
end;
PListRec = ^TListRec;
@ -480,6 +481,9 @@ begin
sConnName := ExtractConnectionName(sPath);
RemotePath := ExtractRemoteFileName(sPath);
Result:= FtpConnect(sConnName, FtpSend);
if Result then begin
RemotePath:= FtpSend.ClientToServer(RemotePath);
end;
end;
function LocalFindNext(Hdl: THandle; var FindData: TWin32FindData): Boolean;
@ -522,7 +526,7 @@ begin
if I < FtpList.Count then
begin
FillChar(FindData, SizeOf(FindData), 0);
StrPCopy(FindData.cFileName, FtpList.Items[I].FileName);
StrPCopy(FindData.cFileName, FtpSend.ServerToClient(FtpList.Items[I].FileName));
FindData.dwFileAttributes := FindData.dwFileAttributes or FILE_ATTRIBUTE_UNIX_MODE;
if FtpList.Items[I].Directory then
FindData.dwFileAttributes := FindData.dwFileAttributes or FILE_ATTRIBUTE_DIRECTORY
@ -574,13 +578,14 @@ begin
try
if GetConnectionByPath(IncludeTrailingPathDelimiter(Path), FtpSend, sPath) then
begin
ListRec.FtpSend := FtpSend;
// Get directory listing
if FtpSend.List(sPath, False) then
begin
if FtpSend.FtpList.Count > 0 then
begin
ListRec.FtpList:= TFTPListEx.Create;
// Save file list
ListRec.FtpList:= TFTPListEx.Create;
ListRec.FtpList.Assign(FtpSend.FtpList);
Result := THandle(ListRec);
RemoteFindNext(Result, FindData);
@ -636,7 +641,8 @@ begin
Result := FS_EXEC_OK
else
begin
sFileName:= SetDirSeparators(RemoteName + FtpSend.GetCurrentDir);
sFileName := FtpSend.ServerToClient(FtpSend.GetCurrentDir);
sFileName := SetDirSeparators(RemoteName + sFileName);
StrPLCopy(RemoteName, sFileName, MAX_PATH);
Result := FS_EXEC_SYMLINK;
end;
@ -705,6 +711,7 @@ begin
else if GetConnectionByPath(OldName, FtpSend, sOldName) then
begin
sNewName := ExtractRemoteFileName(NewName);
sNewName := FtpSend.ClientToServer(sNewName);
ProgressProc(PluginNumber, OldName, NewName, 0);
if FtpSend.RenameFile(sOldName, sNewName) then
begin