Previously written by an FTP client to download the gadget. Supporting the continuation of the breakpoint, multithreading transmission, etc. (in fact, is not a real multi-threaded transmission and download mode, is a pseudo-multithreading, just more open the FTP port, after the connection from the location of the specified data section to start downloading, So in order to realize the real meaning of a multithreaded mode or need to do the corresponding processing in the server to achieve. The code is very simple, just provide a download method, pass an FTP format URL and then parse out the actual address and file name and so on to start implementation of the download. Approximate code:
{ ******************************************************* } {} {Cannot studio FTP client download control unit} {ftpclient} {Author: not cannot February 25, 2009, 9:09:04} {} {} {******************************************* Unit ftpclient; Interface uses windows,classes,sysutils,strutils,scktcomp,wininet, messages,forms,inifiles; Type tdxftpclient = class; Tdxsockstate = (ds_dataok,ds_userterminate,ds_dataerr); Treadwritethread = Class (TThread) private fdatasocket:tclientsocket; Owner:tdxftpclient; Socketdatastream:twinsocketstream; Procedure DownLoad; Procedure UpLoad; protected procedure Execute; Override; Procedure UpdateProgress; Public constructor Create (Bsuspend:boolean; Aownerftp:tdxftpclient; host:string; Port:word); destructor Destroy; Override; End; TDXFTP = class; {FTP dual-line connection, data connection and command connection} Tdxftpclient = Class (tcomponent) private fcmdsocket:tclientsocket; The data connection is connected with the command datastream:tmemorystream; protected Datasize,readysize:int64; Ownerftp:tdxftp; Socketindex:integer; Readwritethread:treaDwritethread; user,password,dirname,filename,host:string; Conport:word; Procedure Docmdsocketread (Sender:tobject; Socket:tcustomwinsocket); Procedure Docmdsocketerror (Sender:tobject; Socket:tcustomwinsocket; Errorevent:terrorevent; var errorcode:integer); Procedure Doreadwriteend (Sender:tobject); Public constructor Create (aowner:tcomponent); Override; destructor Destroy; Override; Procedure Open; End; Download Start Event, conindex specifies the download thread number, startpos and totalsize Specify the download start location and total amount of data respectively tondownstartevent = procedure (sender:tobject;conindex : Integer;startpos,totalsize:int64) of object; Progress events, respectively specified as current progress, and download speed tonprogressevent = procedure (sender:tobject; Const Filereadysize,filetotalsize:int64; Const Progress:single; Const readwriterate:single) of object; Upload the event triggered when the download completes, readystate specifies the completed state tonupdownreadyevent = procedure (sender:tobject; Const filereadysize,filetotalsize : Int64; Const readystate:tdxsockstate) of object; When downloading and uploading, the event that sockstream triggers when reading and writing data fails. Waitagain indicates whether to continue waiting for the next read and write, by default is notWait,//If not wait, direct abort data transfer, or wait until there is data read and write///If not specified, automatically detected 10 times, if more than 10 did not read or write data, representing the exception, transmission data aborted tsocketerror = procedure ( Sender:tobject; Errorevent:terrorevent; var errorcode:integer) of object; Treadwritdataerrevent = procedure (sender:tobject; var Waitagain:boolean {continue to wait}) of object; Tdxftp = Class (tcomponent) private fthreadcount:integer; Ftpsocketarr:array of Tdxftpclient; Ini:tmeminifile; Filetotalsize:int64; Fondownstart:tondownstartevent; Fonprogress:tonprogressevent; Readycount:integer; The number of Downstarttick:dword performed; Beginsize:int64; savefilename:string; Userterminated:boolean; User terminates criticalsection:trtlcriticalsection; Create a critical zone filestream:tfilestream; Savefileintime:boolean; Real-time Save data file Isupload:boolean; Fonupdownready:tonupdownreadyevent; Sockstate:tdxsockstate; Fonreadwritedataerror:treadwritdataerrevent; Fonsocketerror:tsocketerror; Procedure Setthreadcount (const value:integer); function Getactive:boolean; Procedure Downready; All done, file Merge ProCedure Ready; Public constructor Create (aowner:tcomponent); Override; destructor Destroy; Override; Property Threadcount:integer Read Fthreadcount write setthreadcount default 2; Number of threads procedure Suspend; Suspension of procedure Resume; continue to procedure Terminate; Terminate data transfer property Active:boolean read getactive; Whether the activity procedure DownLoad (const fpturl:string; savetofile:string; Const Saveintime:boolean = False); Download procedure UpLoad (const filename,ftpurl:string); Procedure Savecfg (cfgfile:string); Build configuration file Property Ondownstart:tondownstartevent read Fondownstart write Fondownstart; Property Onprogress:tonprogressevent read Fonprogress write fonprogress; Property Onupdownready:tonupdownreadyevent read Fonupdownready write Fonupdownready; Property Onreadwritedataerror:treadwritdataerrevent read Fonreadwritedataerror write fonreadwritedataerror; Property Onsocketerror:tsocketerror read Fonsocketerror write fonsocketerror; End; function Checkfilename (const FILENAME:STRING): string; function Rightpos (const substr,str:string; const Index:integer =-1): integer; Implementation const RECVTMPBUFSIZE = 64 * 1024; End.
This default address is a download from the snow on an example, the specific code download (2007 under test)