WEB开发网
开发学院软件开发VC FTP多线程切割传输 阅读

FTP多线程切割传输

 2008-09-23 19:27:14 来源:WEB开发网   
核心提示: 2.FTP线程类unitUnitFtpPhotoData;interfaceusesWindows,SysUtils,Variants,Classes,StdCtrls,Controls,IdBaseComponent,IdComponent,IdTCPConnection,IdTCPCl

2.FTP线程类

unitUnitFtpPhotoData;
interface
uses
 Windows,SysUtils,Variants,Classes,StdCtrls,Controls,IdBaseComponent,
 IdComponent,IdTCPConnection,IdTCPClient,IdFTP,
 IdThreadComponent,IdAntiFreezeBase,IdAntiFreeze,Dialogs;
const
 ZZ_FTP_IP='127.0.0.1';
 ZZ_FTP_PORT=21;
type
 TFtpPhotoData=class(TIdFtp)
 private
  {Privatedeclarations}
 public
  procedureCreateFtpThread(idFTP:TIdFTP;aUserName,aPassword,
               aOrgFileName,aDestFileName:string);
  procedureDoWork(AWorkMode:TWorkMode;constACount:Integer);override;
  procedureEndWork(AWorkMode:TWorkMode);override;
 published
  {Publisheddeclarations}
  {公布子组件的事件}
  {Publicdeclarations}
 end;
type
 TFtpThread=class(TIdThreadComponent)
 private
 public
end;
implementation
{TFtpPhotoData}
procedureTFtpPhotoData.CreateFtpThread(idFTP:TIdFTP;aUserName,aPassword,
                   aOrgFileName,aDestFileName:string);
begin
 idFtp.Host:=ZZ_FTP_IP;
 idFtp.Port:=ZZ_FTP_PORT;
 idFtp.Username:=aUserName;
 idFtp.Password:=aPassword;
 try
  idFtp.Connect;
  ifnotidFtp.Connectedthenbegin
    //MsgBox('');
   endelsebegin
    idFtp.Put(aOrgFileName,aDestFileName,false);
    //idFtp.
   end;
  except
   idFtp.Quit;
  end;
end;
procedureTFtpPhotoData.DoWork(AWorkMode:TWorkMode;constACount:Integer);
begin
 ifACount=100thenbegin
   showMessage('finishThread');
 end;
end;
procedureTFtpPhotoData.EndWork(AWorkMode:TWorkMode);
begin
 showMessage('finishThread');
 //
end;
end.

3.调用程序

//TIdThreadComponent;TIdAntiFreeze;不常用的控件,线程和冻结
procedureTFrm_Ftp.IdThreadComponent_FtpRun(Sender:TIdCustomThreadComponent);
var
 f:TIdFTP;
 i:integer;
begin
 f:=TIdFTP.Create(Self);
 try
  f.Username:='ftp';
  f.Password:='ftp';
  f.Host:='127.0.0.1';
  f.Port:=21;
  ifFThreadNumber>3thenbegin
   self.IdThreadComponent_Ftp.Terminate;
   self.IdThreadComponent_Ftp.Active:=False;
    exit;
  end;
   try
    f.Connect;
    f.Put(FFileNameList[FThreadNumber],ExtractFileName(FFileNameList[FThreadNumber]),False);
    sleep(10000);
    f.Quit;
    self.IdThreadComponent_Ftp.Terminate;
   except
   end;
 finally
  f.Free;
 end;
 inc(FThreadNumber);
end;

放在BLOG上,以后有机会再用,免得忘了。

上一页  1 2 

Tags:FTP 线程 切割

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接