📄 srvctrl.pas
字号:
end;
s:=addslash(Parent.DirList[i])+s1;
i:=Parent.DirList.IndexOf(s);
if i < 0 then
begin
SendString('450 Directory not found');
continue;
end;
rmdir(Parent.DirList.Alias[i]);
if ioresult <> 0 then
begin
SendString('550 Not empty');
continue;
end;
Parent.DirList.Delete(i);
SendString('250 Directory removed');
end;
25: { MKD }
begin
{ Creates a virtual directory }
if (State <> st_DIALOG) and (State <> st_DATA) then
begin
SendString('530 Not logged in');
Continue;
end;
{ Checking the directory permissions }
par:=alltrim(par);
if par[length(par)] in ['/','\'] then setlength(par,length(par)-1);
s:=par;
while (s <> '') and not (s[length(s)] in ['\','/']) do dec(byte(s[0]));
s1:=copy(par,length(s)+1,255);
if s = '' then
s:=CDir
else
if not (s[1] in ['/','\']) then
s:=addslash(CDir)+s;
s:=NormalizePath(s);
i:=Parent.DirList.IndexOf(s);
if i < 0 then
begin
SendString('450 Parent directory not found');
continue;
end;
if not Parent.UserList.RootByName(Usr) then
begin
if Parent.DirList.UID[i] <> Parent.UserList.UIDByName(Usr) then
begin
if Parent.UserList.InGroupByName(Usr,Parent.DirList.GID[i]) then
begin
if not (da_GrWriteFiles in Parent.DirList.Attrib[i]) then
begin
SendString('550 Permission denied');
continue;
end;
end
else
if not (da_WriteFiles in Parent.DirList.Attrib[i]) then
begin
SendString('550 Permission denied');
continue;
end;
end;
end;
s:=addslash(Parent.DirList.Alias[i])+s1;
mkdir(s);
if ioresult <> 0 then
begin
SendString('550 Can''t create directory');
continue;
end;
s1:=addslash(Parent.DirList[i])+s1;
if Parent.DirList.AddDir(s1,s,
[da_GrReadList,da_GrReadFiles,da_GrEnter],Parent.UserList.UIDByName(usr),
Parent.UserList.GIDByName(usr,1)) = -1 then
SendString('550 Can''t create directory')
else
SendString('257 Directory has been created');
end;
26: { PWD }
begin
SendString('257 "'+CDir+'"');
end;
27: { LIST }
begin
if (State <> st_DIALOG) and (State <> st_DATA) then
begin
SendString('530 Not logged in');
Continue;
end;
lst:=TListFiller.Create;
if par = '' then
lst.FillFrom(CDir,di_LIST,Usr,Parent)
else
begin
if par[1] in ['/','\'] then
lst.FillFrom(par,di_LIST,Usr,Parent)
else
if CDir[byte(CDir[0])] in ['/','\'] then
lst.FillFrom(CDir+par,di_LIST,Usr,Parent)
else
lst.FillFrom(CDir+'/'+par,di_LIST,Usr,Parent);
end;
if DCon then
begin
DTrd.GotWork('DIR',di_LIST,CMode,CData,lst,'0');
if par[1] in ['/','\'] then
SendString('125 Sending list for "'+par+'"')
else
if CDir[byte(CDir[0])] in ['/','\'] then
SendString('125 Sending list for "'+CDir+par+'"')
else
SendString('125 Sending list for "'+CDir+'/'+par+'"');
end
else
begin
DTrd:=TDataThread.Create('DIR',RAddr,Pasv,di_LIST,CMode,CData,DPort,
Parent,lst,'0',DConExit,ControlLog,Usr,Pwd,CDir);
DCon:=true;
if par[1] in ['/','\'] then
SendString('150 Sending list for "'+par+'"')
else
if CDir[byte(CDir[0])] in ['/','\'] then
SendString('150 Sending list for "'+CDir+par+'"')
else
SendString('150 Sending list for "'+CDir+'/'+par+'"');
end;
if DTrd.Error = 0 then
begin
State:=st_DATA;
TOut:=TTimeout.create(600,@Brk);
end
else
begin
DTrd.Terminate;
SendString('425 Can''t open data connection.');
end;
end;
28: { NLST }
begin
if (State <> st_DIALOG) and (State <> st_DATA) then
begin
SendString('530 Not logged in');
Continue;
end;
lst:=TListFiller.Create;
if par = '' then
lst.FillFrom(CDir,di_LIST,Usr,Parent)
else
begin
if par[1] in ['/','\'] then
lst.FillFrom(par,di_NLST,Usr,Parent)
else
if CDir[byte(CDir[0])] in ['/','\'] then
lst.FillFrom(CDir+par,di_NLST,Usr,Parent)
else
lst.FillFrom(CDir+'/'+par,di_NLST,Usr,Parent);
end;
if DCon then
begin
DTrd.GotWork('DIR',di_LIST,CMode,CData,lst,'0');
if par[1] in ['/','\'] then
SendString('125 Sending list for "'+par+'"')
else
if CDir[byte(CDir[0])] in ['/','\'] then
SendString('125 Sending list for "'+CDir+par+'"')
else
SendString('125 Sending list for "'+CDir+'/'+par+'"');
end
else
begin
DTrd:=TDataThread.Create('DIR',RAddr,Pasv,di_LIST,CMode,CData,DPort,
Parent,lst,'0',DConExit,ControlLog,Usr,Pwd,CDir);
DCon:=true;
if par[1] in ['/','\'] then
SendString('150 Sending list for "'+par+'"')
else
if CDir[byte(CDir[0])] in ['/','\'] then
SendString('150 Sending list for "'+CDir+par+'"')
else
SendString('150 Sending list for "'+CDir+'/'+par+'"');
end;
if DTrd.Error = 0 then
begin
State:=st_DATA;
TOut:=TTimeout.create(600,@Brk);
end
else
begin
DTrd.Terminate;
SendString('425 Can''t open data connection.');
end;
end;
29: { SITE }
begin
SendString('502 Command "'+cmd+'" not implemented');
end;
30: { SYST }
begin
SendString('215 IBM-PC (Windows95/98/NT based system)');
end;
31: { STAT }
begin
SendString('502 Command "'+cmd+'" not implemented');
continue;
end;
32: { HELP }
begin
SendString('214-The following commands are recognized:');
SendString(' ABOR DELE NOOP REIN SITE SYST XRMD');
SendString(' ACCT HELP PASS REST SMNT TYPE SIZE');
SendString(' ALLO LIST PASV RETR STAT USER');
SendString(' APPE MKD PORT RMD STOR XCWD');
SendString(' CDUP MODE PWD RNFR STOU XMKD');
SendString(' CWD NLST QUIT RNTO STRU XPWD');
SendString('214 Send comments to drtinus@yahoo.com');
end;
33: { SIZE }
begin
if (State <> st_DIALOG) and (State <> st_DATA) then
begin
SendString('530 Not logged in');
Continue;
end;
{ Checking directory permissions }
par:=alltrim(par);
if par[length(par)] in ['/','\'] then
begin
SendString('450 No file name specified');
continue;
end;
s:=par;
while (s <> '') and not (s[length(s)] in ['\','/']) do dec(byte(s[0]));
s1:=copy(par,length(s)+1,255);
if s = '' then s:=CDir;
s:=NormalizePath(s);
i:=Parent.DirList.IndexOf(s);
if i < 0 then
begin
SendString('450 Directory not found');
continue;
end;
if not Parent.UserList.RootByName(Usr) then
begin
if Parent.DirList.UID[i] <> Parent.UserList.UIDByName(Usr) then
begin
if Parent.UserList.InGroupByName(Usr,Parent.DirList.GID[i]) then
begin
if not (da_GrReadList in Parent.DirList.Attrib[i]) then
begin
SendString('450 Permission denied');
continue;
end;
end
else
if not (da_ReadList in Parent.DirList.Attrib[i]) then
begin
SendString('450 Permission denied');
continue;
end;
end;
end;
{ Processing command }
s:=addslash(Parent.DirList.Alias[i])+s1;
if FindFirst(s,faArchive+faHidden+faReadOnly,SR) <> 0 then
begin
FindClose(SR);
SendString('450 File not found');
continue;
end;
FindClose(SR);
SendString(format('213 %u',[SR.Size]));
end;
34: { MDTM }
begin
if (State <> st_DIALOG) and (State <> st_DATA) then
begin
SendString('530 Not logged in');
Continue;
end;
{ Checking directory permissions }
par:=alltrim(par);
if par[length(par)] in ['/','\'] then
begin
SendString('450 No file name specified');
continue;
end;
s:=par;
while (s <> '') and not (s[length(s)] in ['\','/']) do dec(byte(s[0]));
s1:=copy(par,length(s)+1,255);
if s = '' then s:=CDir;
s:=NormalizePath(s);
i:=Parent.DirList.IndexOf(s);
if i < 0 then
begin
SendString('450 Directory not found');
continue;
end;
if not Parent.UserList.RootByName(Usr) then
begin
if Parent.DirList.UID[i] <> Parent.UserList.UIDByName(Usr) then
begin
if Parent.UserList.InGroupByName(Usr,Parent.DirList.GID[i]) then
begin
if not (da_GrReadList in Parent.DirList.Attrib[i]) then
begin
SendString('450 Permission denied');
continue;
end;
end
else
if not (da_ReadList in Parent.DirList.Attrib[i]) then
begin
SendString('450 Permission denied');
continue;
end;
end;
end;
{ Processing command }
s:=addslash(Parent.DirList.Alias[i])+s1;
if FindFirst(s,faArchive+faHidden+faReadOnly,SR) <> 0 then
begin
FindClose(SR);
SendString('450 File not found');
continue;
end;
FindClose(SR);
ftm:=SR.FindData.ftLastWriteTime;
FileTimeToLocalFileTime(ftm,lftm);
FileTimeToSystemTime(lftm,stm);
SendString(format('213 %4.4u%2.2u%2.2u%2.2u%2.2u%2.2u',[stm.wYear,stm.wMonth,stm.wDay,stm.wHour,stm.wMinute,stm.wSecond]));
end;
else
begin
SendString('502 Command "'+cmd+'" not implemented');
end;
end;
end
else
begin
if State = st_DATA then
begin
if CData = dt_STREAM then
begin
if not DCon then
begin
SendString('226 Transfer complete');
State:=st_DIALOG;
if not Brk then TOut.terminate;
end
else if Brk then
begin
if DCon then DTrd.terminate;
handleerror(ES_STOUT);
State:=st_DIALOG;
end;
end
else
begin
if DTrd.Dir = di_IDLE then
begin
SendString('250 Transfer complete');
State:=st_DIALOG;
if not Brk then TOut.terminate;
Marker:='0';
end
else if Brk then
begin
if DCon then DTrd.terminate;
handleerror(ES_STOUT);
State:=st_DIALOG;
Marker:='0';
end;
end;
end;
sleep(100);
end;
end;
end;
procedure TSrvCtrlThread.HandleError(ErrNo : integer);
begin
Error:=ErrNo;
LogMessage(ErrNo);
end;
procedure TSrvCtrlThread.Synchronized;
begin
if assigned(ControlLog) then ControlLog(self,Res);
end;
procedure TSrvCtrlThread.LogMessage(MsgNo : integer);
begin
Messg:=MsgNo;
Synchronize(Synchronized);
Error:=0;
Messg:=0;
end;
var
i : word;
begin
for i:=1 to MaxConn do
ProcessList[i]:=nil;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -