ReceiveHTTPFile()

Syntax

Result = ReceiveHTTPFile(URL$, Filename$ [, Flags [, UserAgent$]])
Description
Download a file to disk from the given URL$.

Parameters

URL$ The URL to download from.
Filename$ The local filename to write the file to. If the filename does not include a full path, it is interpreted relative to the current directory. If the file exists, it will be overwritten.
Flags (optional) It can be a combination of the following values:
  #PB_HTTP_Asynchronous: starts the download asynchronously.
  #PB_HTTP_NoRedirect  : don't follow automatic redirections.
UserAgent$ (optional) Change the user agent for the HTTP request. Default user agent is set to "Mozilla/5.0 Gecko/41.0 Firefox/41.0" for maximum compatibility.

Return value

Returns nonzero if the download was successful, zero otherwise. If #PB_HTTP_Asynchronous was specified, it returns the 'HttpConnection' value needed for HTTPProgress(), AbortHTTP() and FinishHTTP(). When using #PB_HTTP_Asynchronous, FinishHTTP() needs to be called when the download is finished (successfully or not).

Remarks

On Linux, 'libcurl' needs to be installed to have this command working (most of Linux distributions comes with it already installed).
If the remote file was not found, it will contains the webserver error.

Example

  Filename$ = SaveFileRequester("Where to save index.php ?", "", "", 0)

  If ReceiveHTTPFile("https://www.purebasic.com/index.php", Filename$)
    Debug "File received and written to disk. If the remote file was not found, it will contains the webserver error."
  Else
    Debug "No file received (network error)."
  EndIf

See Also

URLEncoder()

Supported OS

All

<- HTTPTimeout() - Http Index - ReceiveHTTPMemory() ->