Downloads a resource from the Internet and saves them to a file.

UrlDownloadToFileEx(cUrl, cLocalFile [, cCallback [, bAsyncronous]])

Parameters

cUrl

The url to download, the protocal prefix (e.g. http://, ftp:// ) has to be included!

cLocalFile

The download location - a valid local filename.

cCallback (optional)

The callback function to call to report progress during the download.

The callback function must have the following prototype:

FUNCTION UrlProgress
LPARAMETERS ulProgress, ulProgressMax, ulStatusCode
ENDFUNC

parameter meanings:
ulProgress = bytes downloaded
ulProgressMax = size of resource downloaded
ulStatusCode = reason of callback

ulStatusCode can be one of the following:

ValueMeaning
BINDSTATUS_DOWNLOADINGDATAA new chunk of data has arrived.
BINDSTATUS_FINDINGRESOURCEThe url gets resolved.
BINDSTATUS_CONNECTINGConnecting.
BINDSTATUS_REDIRECTINGRedirecting.
BINDSTATUS_BEGINDOWNLOADDATAThe download begins.
BINDSTATUS_ENDDOWNLOADDATAThe download has finished, file is now in the local IE cache.
BINDSTATUS_DOWNLOAD_FINISHEDThe download is now ready to be read from the supplied file destination.
BINDSTATUS_DOWNLOAD_ABORTEDThe download was aborted (through AbortUrlDownloadToFileEx or release of the FLL).
BINDSTATUS_USINGCACHEDCOPY The file is found in the IE cache and is not redownloaded.
BINDSTATUS_SENDINGREQUESTThe file is requested.
bAsyncronous (optional)

default = .F.

If .T. is passed the download is executed asyncronous in a seperate thread, the function returns immediately.
Otherwise the download is executed syncronously and the function returns when the download has finished.

Progress callback works for both types.

To abort an asyncronous download you have to call AbortUrlDownloadToFileEx with the numeric handle value returned from UrlDownloadToFileEx.
To abort a syncronous download you have to return .F. from the callback function.

Return Value

If the download is syncronous the function returns the result from the UrlDownloadToFile API (HRESULT | < 0 failure | > 0 success).
If the download is asyncronous the function returns an internal handle representing the thread which executes the download.

See Also

Reference

AbortUrlDownloadToFileEx
AIpAddresses
ANetFiles
ANetServers
GetServerTime
IcmpPing
Ip2MacAddress
ResolveHostToIp
SyncToSNTPServer

Used WinApi functions

URLDownloadToFile