function HTTP_FileSize(AHTTP: THTTPSend; AURL: string): int64; { //SZ To get size of the file on HTTP request AHTTP - HTTP instance AURL - URL of the file } var head: string; i: integer; Size: int64; begin Size := 0; try AHTTP.Headers.Clear; AHTTP.Document.Clear; AHTTP.HTTPMethod('HEAD', AURL); head := AHTTP.Headers.Text; i := pos('content-length', LowerCase(head)); if i > 0 then begin inc(i, 14); // Skip colon and white space chars while i <= length(head) do begin if not (head[i] in [' ', ':',#9, #10, #13]) then break; inc(i); end; while i <= length(head) do begin if head[i] in ['0'..'9'] then Size := Size * 10 + ord(head[i]) - 48 else break; inc(i); end; end; AHTTP.Headers.Clear; AHTTP.Document.Clear; finally end; Result := Size; end; procedure TDownloadDaemon.Execute; begin Fsockreadcount:=0; Fsockwritecount:=0; LastRead:=0; LastWrite:=0; FFileSize := 0; if protocol=prHttp then begin phttp^.Sock.OnStatus:=@SockStatus; //SZ Added code to retrieve file size for download progress FFileSize := HTTP_FileSize(phttp^, Durl); ok:=phttp^.HTTPMethod('GET', Durl) end else if protocol=prFtp then begin pftp^.OnStatus:=@FTPStatus; if pftp^.Login then begin pftp^.ChangeWorkingDir(Dftpdir); //SZ FFileSize := pftp^.FileSize(Dftpfile); ok:=pftp^.RetrieveFile(Dftpfile,false); end; end; if Assigned(FonDownloadComplete) then Synchronize(FonDownloadComplete); end;