📄 ftpsrv.pas
字号:
Client : TFtpCtrlSocket;
UserName : String;
PassWord : String;
var Authenticated : Boolean);
begin
if Assigned(FOnAuthenticate) then
FOnAuthenticate(Self, Client, UserName, Password, Authenticated);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerChangeDirectory(
Client : TFtpCtrlSocket;
Directory : String;
var Allowed : Boolean);
begin
if Assigned(FOnChangeDirectory) then
FOnChangeDirectory(Self, Client, Directory, Allowed);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerMakeDirectory(
Client : TFtpCtrlSocket;
Directory : String;
var Allowed : Boolean);
begin
if Assigned(FOnMakeDirectory) then
FOnMakeDirectory(Self, Client, Directory, Allowed);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerBuildDirectory(
Client : TFtpCtrlSocket;
var Params : TFtpString;
Detailed : Boolean);
begin
if Assigned(FOnBuildDirectory) then
FOnBuildDirectory(Self, Client, Params, Detailed);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerAlterDirectory(
Client : TFtpCtrlSocket;
var Params : TFtpString;
Detailed : Boolean);
begin
if Assigned(FOnAlterDirectory) then
FOnAlterDirectory(Self, Client, Params, Detailed);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerSendAnswer(
Client : TFtpCtrlSocket;
var Answer : TFtpString);
begin
if Assigned(FOnAnswerToClient) then
FOnAnswerToClient(Self, Client, Answer);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerClientDisconnect(Client : TFtpCtrlSocket; Error : Word);
begin
if Assigned(FOnClientDisconnect) then
FOnClientDisconnect(Self, Client, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerClientConnect(Client : TFtpCtrlSocket; Error : Word);
begin
if Assigned(FOnClientConnect) then
FOnClientConnect(Self, Client, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerStorSessionConnected(
Client : TFtpCtrlSocket; Data : TWSocket; Error : Word);
begin
if Assigned(FOnStorSessionConnected) then
FOnStorSessionConnected(Self, Client, Data, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerRetrSessionConnected(
Client : TFtpCtrlSocket; Data : TWSocket; Error : Word);
begin
if Assigned(FOnRetrSessionConnected) then
FOnRetrSessionConnected(Self, Client, Data, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerStorSessionClosed(
Client : TFtpCtrlSocket; Data : TWSocket; Error : Word);
begin
if Assigned(FOnStorSessionClosed) then
FOnStorSessionClosed(Self, Client, Data, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerRetrSessionClosed(
Client : TFtpCtrlSocket; Data : TWSocket; Error : Word);
begin
if Assigned(FOnRetrSessionClosed) then
FOnRetrSessionClosed(Self, Client, Data, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerClientCommand(
Client : TFtpCtrlSocket;
var Keyword : TFtpString;
var Params : TFtpString;
var Answer : TFtpString);
begin
if Assigned(FOnClientCommand) then
FOnClientCommand(Self, Client, KeyWord, Params, Answer);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerValidatePut(
Client : TFtpCtrlSocket;
var FilePath : TFtpString;
var Allowed : Boolean);
begin
if Assigned(FOnValidatePut) then
FOnValidatePut(Self, Client, FilePath, Allowed);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerValidateDele(
Client : TFtpCtrlSocket;
var FilePath : TFtpString;
var Allowed : Boolean);
begin
if Assigned(FOnValidateDele) then
FOnValidateDele(Self, Client, FilePath, Allowed);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerValidateGet(
Client : TFtpCtrlSocket;
var FilePath : TFtpString;
var Allowed : Boolean);
begin
if Assigned(FOnValidateGet) then
FOnValidateGet(Self, Client, FilePath, Allowed);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerStorDataAvailable(
Client : TFtpCtrlSocket;
Data : TWSocket;
Buf : PChar;
Len : LongInt;
Error : Word);
begin
if Assigned(FOnStorDataAvailable) then
FOnStorDataAvailable(Self, Client, Data, Buf, Len, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.TriggerRetrDataSent(
Client : TFtpCtrlSocket;
Data : TWSocket;
Error : Word);
begin
if Assigned(FOnRetrDataSent) then
FOnRetrDataSent(Self, Client, Data, Error);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.CommandUSER(
Client : TFtpCtrlSocket;
var Keyword : TFtpString;
var Params : TFtpString;
var Answer : TFtpString);
begin
Client.CurCmdType := ftpcUSER;
Client.UserName := Trim(Params);
Client.FtpState := ftpcWaitingPassword;
Answer := Format(msgPassRequired, [Client.UserName]);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.CommandPASS(
Client : TFtpCtrlSocket;
var Keyword : TFtpString;
var Params : TFtpString;
var Answer : TFtpString);
var
Authenticated : Boolean;
begin
if Client.FtpState <> ftpcWaitingPassword then
Answer := msgNoUser
else begin
Client.CurCmdType := ftpcPASS;
Client.PassWord := Trim(Params);
Authenticated := TRUE;
TriggerAuthenticate(Client, Client.UserName, Client.PassWord, Authenticated);
if Authenticated then begin
Client.FtpState := ftpcReady;
Client.Directory := Client.HomeDir;
Answer := Format(msgLogged, [Client.UserName])
end
else begin
Client.FtpState := ftpcWaitingUserCode;
Answer := msgLoginFailed;
end;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.CommandCDUP(
Client : TFtpCtrlSocket;
var Keyword : TFtpString;
var Params : TFtpString;
var Answer : TFtpString);
begin
if Client.FtpState <> ftpcReady then begin
Answer := msgNotLogged;
Exit;
end;
Client.CurCmdType := ftpcCDUP;
Params := '..';
CommandChangeDir(Client, Keyword, Params, Answer);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.CommandCWD(
Client : TFtpCtrlSocket;
var Keyword : TFtpString;
var Params : TFtpString;
var Answer : TFtpString);
begin
if Client.FtpState <> ftpcReady then begin
Answer := msgNotLogged;
Exit;
end;
Client.CurCmdType := ftpcCWD;
CommandChangeDir(Client, Keyword, Params, Answer);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function SlashesToBackSlashes(const S : String) : String;
var
I : Integer;
begin
Result := S;
for I := 1 to Length(Result) do begin
if Result [I] = '/' then
Result[I] := '\';
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function BackSlashesToSlashes(const S : String) : String;
var
I : Integer;
begin
Result := S;
for I := 1 to Length(Result) do begin
if Result [I] = '\' then
Result[I] := '/';
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TFtpServer.CommandChangeDir(
Client : TFtpCtrlSocket;
var Keyword : TFtpString;
var Params : TFtpString;
var Answer : TFtpString);
var
Allowed : Boolean;
OldDir : String;
begin
OldDir := Client.Directory;
try
Params := SlashesToBackSlashes(Params);
Client.Directory := Trim(Params);
Allowed := TRUE;
TriggerChangeDirectory(Client, Client.Directory, Allowed);
if Allowed then
Answer := Format(msgCWDSuccess,
[BackSlashesToSlashes(Client.Directory)])
else begin
Client.Directory := OldDir;
Answer := Format(msgCWDFailed, ['No permission']);
end;
except
on E:Exception do begin
Client.Directory := OldDir;
Answer := Format(msgCWDFailed, [E.Message]);
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -