Mega Code Archive

 
Categories / Delphi / Examples
 

Download a file from the web [internet]

Question: Is there an easy function to download a file via http protocol? Answer: Yes, there is. It's called UrlDownloadToFile() and it's defined in unit URLMon. The code below shows how to use it. uses URLMon; //------------------------------------------------------------- // SourceFile = http address e.g. http://www.ibm.com/test.gif // DestFile = filename where to save the file // function DownloadFile(SourceFile, DestFile: string): Boolean; begin try Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; except Result := False; end; end;