sunkiss:
indy下的IDFTPSERVER就是支持多线程,你可在里面设置连接数!我就写了一个,给你一些例子吧;
IdFTPServer1.DefaultDataPort := 20 ;
IdFTPServer1.DefaultPort := Ini_F.ReadInteger('Ftp','Ftp_DataPort',21 ) ;
IdFTPServer1.MaxConnections := Ini_F.ReadInteger('Ftp','Ftp_MaxNum',23 ) ;
IdFTPServer1.AllowAnonymousLogin := Ini_F.ReadBool('Ftp','Ftp_Anony' , False ) ;
IdFTPServer1.Greeting.Text.Clear ;
IdFTPServer1.Greeting.Text.Add(Ini_F.ReadString('Ftp','Ftp_salutatory','Ftp Server 已准备(For DOS系统)') ) ;
IdFTPServer1.AnonymousPassStrictCheck := False ;
IdFTPServer1.EmulateSystem := ftpsDOS ; //ftpsUNIX;
IdFTPServer1.HelpReply.text := 'Help is not implemented';
IdFTPServer1.OnChangeDirectory := IdFTPServer1ChangeDirectory;
IdFTPServer1.OnGetFileSize := IdFTPServer1GetFileSize;
IdFTPServer1.OnListDirectory := IdFTPServer1ListDirectory;
IdFTPServer1.OnUserLogin := IdFTPServer1UserLogin;
IdFTPServer1.OnMakeDirectory := IdFTPServer1MakeDirectory;
IdFTPServer1.OnRemoveDirectory := IdFTPServer1RemoveDirectory;
IdFTPServer1.Greeting.NumericCode := 220;
IdFTPServer1.OnDisconnect := IdFTPServer1DisConnect;
function Txgy_Ftp_Frm.GetNewDirectory( old, action: string ) : string;
var
a: integer;
begin
if action = '../' then
begin
if old = '/' then
begin
result := old;
exit;
end;
a := length( old ) - 1;
while ( old[a] <> '/' ) and ( old[a] <> '/' ) do
dec( a ) ;
result := copy( old, 1, a ) ;
exit;
end;
if ( action[1] = '/' ) or ( action[1] = '/' ) then
result := action
else
result := old + action;
end;
procedure Txgy_Ftp_Frm.IdFTPServer1ListDirectory( ASender: TIdFTPServerThread; const APath: string; ADirectoryListing: TIdFTPListItems ) ;
var
LFTPItem :TIdFTPListItem;
SR : TSearchRec;
SRI : Integer;
begin
SRI := FindFirst(AppDir + '/*.*', faAnyFile - faHidden - faSysFile, SR);
While SRI = 0 do
begin
LFTPItem := ADirectoryListing.Add;
LFTPItem.FileName := SR.Name;
LFTPItem.Size := SR.Size;
LFTPItem.ModifiedDate := FileDateToDateTime(SR.Time);
if SR.Attr = faDirectory then
LFTPItem.ItemType := ditDirectory
else
LFTPItem.ItemType := ditFile;
SRI := FindNext(SR);
end;
FindClose(SR);
SetCurrentDir(AppDir + APath + '/..');
end;
procedure Txgy_Ftp_Frm.IdFTPServer1RetrieveFile( ASender: TIdFTPServerThread;
const AFilename: string; var VStream: TStream ) ;
var
Str_T : String ;
begin
VStream := TFileStream.Create(ReplaceChars(AFilename),fmOpenRead);
Str_T := '用户:'+ ASender.Username + FormatDateTime('"于" yyyy"年"mm"月"dd"日" dddd'+' hh:mm:ss AM/PM',now)+',在FTP服务器上下载文件!' ;
Str_T := Str_T + '下载的文件为:' + AFilename ;
Memo1.Lines.Add(Str_T) ;
end;
IdFTPServer1.MaxConnections :为设置最大连接数
另外ASender: TIdFTPServerThread;就是该控件的线程控制参数,因此无须再加线程变量