[SOLVED] LNet, synapse or other way - How to simply make a http file download? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- lazguy · 2010-07-07 17:39 Hello everybody!!! I need to download a .zip file, a .pdf file and a text file from different http addresses on internet. I downloaded LNet component but there is no example showing me how to do this I need. I also downloaded Synapse component but I found the help confused and without examples, so i got confused. I'm looking from something as simple as httpfiledownload('http://somesite.com/somefile.zip','c:\somefolder\som efile.zip') that work both from windows and linux, and, if possible, with no need of any external libraries or files. If possible, if someone can post the code to do that i will be very thank. Thank you very much in advance. ---------------------------------------------------------------------- Laksen · 2010-07-07 17:56 Using synapse you could use something like this: Include httpsend and classes in the uses list Code: [Select]procedure DownloadFile(const Url, PathToSaveTo: string); begin    fs := TFileStream.Create(PathToSaveTo, fmOpenWrite or fmCreate);    try       HttpGetBinary(Url, fs);    finally       fs.Free;    end; end; ---------------------------------------------------------------------- lazguy · 2010-07-08 02:23 Thank you very, very much Laksen !!!!!!!!!!!! it is exactly what i need!!! Problem Solved. ---------------------------------------------------------------------- Almindor · 2010-07-10 12:00 In lNet you can use lnet/examples/console/lhttp/fpget which is exactly like wget (less sophisticated but you get the point). I guess you missed it? ---------------------------------------------------------------------- Lazaruszki · 2010-07-21 08:14 Hi, I use Synaps and this code (Lasken) for file download, but i can't use downloadsize value(httpsend.downloadsize) for progressbar at download time. What is the solution? Need i use multithread? ...or another If somebody can give an working example,  i will be very thank, too. ---------------------------------------------------------------------- theo · 2010-07-21 13:57 You need to process OnStatus: http://synapse.ararat.cz/doku.php/public:howto:onstatus ---------------------------------------------------------------------- Lazaruszki · 2010-07-23 22:42 Hi Theo, I try everything and searching with google but the result is pffffffff Here is my full unit code, if you have a lot of time correct it, please:) . I like write a program that download setup.exe via http and drawing a progressbar. I have 3 errors... unit Unit1; {$mode objfpc}{$H+} interface uses    Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,   StdCtrls, ExtCtrls, Buttons, ComCtrls, ExtDlgs, EditBtn, FileCtrl,   httpsend,blcksock,typinfo, synamisc; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     Edit1: TEdit;     lblout: TLabel;     Lblin: TLabel;     Memo2: TMemo;     ProgressBar1: TProgressBar;     procedure Button1Click(Sender: TObject);     procedure FormCreate(Sender: TObject);     procedure ProgressBar1ContextPopup(Sender: TObject; MousePos: TPoint;       var Handled: Boolean);   private     { private declarations }   public     { public declarations }   end; var   Form1: TForm1;   SizeIn,SizeOut: integer; implementation { TForm1 } type   THookSocketStatus = procedure(Sender: TObject; Reason: THookSocketReason;     const Value: string) of object;   TMemory=pointer;    callback = class        class procedure Status (Sender: TObject; Reason: THookSocketReason; const Value: String);        class procedure Monitor (Sender: TObject; Writing: Boolean; const Buffer: TMemory; Len: Integer);      end; class procedure callback.Status(Sender: TObject; Reason: THookSocketReason;   const Value: String); var v: String; begin   v := getEnumName (typeinfo(THookSocketReason), integer(Reason)) + ' ' + Value;   Form1.Memo2.Lines.Add(v);   if (reason=hr_readcount) then begin                            inc(SizeIN,StrToInt64Def(Value,0));                          //  ProgressBar1.Position := Round(1000 * (CurrentBytes / TotalBytes));                            end;   if (reason=hr_writecount) then      inc(SizeOUT,StrToInt64Def(Value,0));   Form1.lblIN.Caption :=inttostr(SizeIN);   Form1.lblOUT.Caption:=inttostr(SizeOUT);   application.ProcessMessages; end; class procedure callback.Monitor (Sender: TObject; Writing: Boolean; const Buffer: TMemory; Len: Integer); begin   if not writing then      inc(SizeIN, Len)   else      inc(SizeOUT, Len);   Form1.lblIN.Caption :=inttostr(SizeIN);   Form1.lblOUT.Caption:=inttostr(SizeOUT);   application.ProcessMessages; end; procedure TForm1.Button1Click(Sender: TObject);    var   HTTP: THTTPSend;   F: TFileStream;   Start,Size: integer; begin   SizeIN:=0;   SizeOUT:=0;   Memo2.Lines.Add(CRLF+'GET');   Memo2.Lines.Add('------------');   Size:=HttpGetFileSize(Edit1.text); ///  ???   HTTP := THTTPSend.Create;   HTTP.Sock.OnStatus := callback.Status;   //or   HTTP.Sock.OnMonitor := callback.Monitor;      F:=TFileStream.Create('hl.exe',fmcreate);      HttpGetBinary('http://.../upgrade.exe',F);      F.Free; end; procedure TForm1.FormCreate(Sender: TObject); begin end; procedure TForm1.ProgressBar1ContextPopup(Sender: TObject; MousePos: TPoint;   var Handled: Boolean); begin end; initialization   {$I unit1.lrs} end. ---------------------------------------------------------------------- Silvio Clécio · 2010-07-23 23:29 Try this: http://lazarus-br.googlegroups.com/web/DownloadResumeSynapse.7z Good luck. ---------------------------------------------------------------------- evoshroom · 2012-08-08 15:41 I just wanted to say, this thread delivers! ---------------------------------------------------------------------- Fahmy Rofiq · 2012-10-30 05:25 Quote from: silvioprog on July 24, 2010, 01:29:59 amTry this: http://lazarus-br.googlegroups.com/web/DownloadResumeSynapse.7z Good luck. I can't download it, can you reupload please? ---------------------------------------------------------------------- Silvio Clécio · 2012-11-01 00:50 Please see other demo for resuming download in LazSolutions framework: https://github.com/silvioprog/lazsolutions ---------------------------------------------------------------------- delphi887 · 2012-11-26 19:16 hi how do if i want get a file in multi connection in multi part and then join this parts to create file by synapse??? thanks