How to download files from a web server

Sarah Reichelt sarah.reichelt at gmail.com
Fri Jan 6 17:04:44 EST 2006


> > How can I tell when all of the files are finished downloading?
>
> Well, if you're using 'put URL', then it is a blocking command, meaning that
> you don't go to the next script line until it is done downloading. This
> should mean that if you're in a repeat loop, you're finished downloading
> when the repeat loop is over.
>
> The other possibility is to use "load url", which is *non-blocking*, and
> then periodically check the urlStatus of the url you're working on to see
> how far it's gotten.

Or use "load URL with message" which calls a specified handler when
the download is finished e.g.

-- start the download
load URL tURL with message "downloadFinished"

and then a separate handler:

on downloadFinished pURL, pStatus
  if pStatus = "error" then
    -- handle the download failure
  else
   -- transfer the already downloaded data to a variable
   put URL pURL into tDownloadedData
   -- clear the downloaded copy from cache to save memory
   unload URL pURL
  -- process the file
  doStuff tDownloadedData
end downloadFinished

HTH,
Sarah



More information about the use-livecode mailing list