Xbasic

Extension::Curl DownloadMultiple Method

Syntax

.DownloadMultiple as C (files as C)

Arguments

filesCharacter

A CR-LF delimited list of files to download in the form "<local_filename>|<remote_url>".

Returns

resultCharacter

Returns an error message for any files that could not be downloaded. If all downloads succeed, DownloadMultiple() returns an empty string.

Description

Download multiple files.

Discussion

The DownloadMultiple() function downloads a one or more remote files. Files to download are specified as a CR-LF delimited list of file names and URLs.

For example, the following script from an .A5W page downloads 3 zip files to the session folder and displays the local URLs as a comma-delimited list.

<%a
' Generate temporary download filenames:
dim f1 as c = context.request.getRequestTempFileName(".zip")
dim f2 as c = context.request.getRequestTempFileName(".zip")
dim f3 as c = context.request.getRequestTempFileName(".zip")

' Build files list:
dim files as c = ""
files = files + f1 + "|http://peopleplacesthings.com/people.zip" + crlf()
files = files + f2 + "|http://peopleplacesthings.com/places.zip" + crlf()
files = files + f3 + "|http://peopleplacesthings.com/things.zip"

' Do the download:
result = extension::curl::DownloadMultiple(files)

' Check for errors/post process
dim fileURLs[0] as c
if (result <> "" ) then
    ' An error occurred...
    ' Output error and terminate script:
    ? result
    exit
else
    ' success!
    ' Copy to session folder:
    context.session.SaveFileToSessionFile(f1,"people.zip")
    context.session.SaveFileToSessionFile(f2,"places.zip")
    context.session.SaveFileToSessionFile(f3,"things.zip")

    ' Get session folder URL and add to fileURLs array:
    fileURLs.push(context.session.formatFileDataURL("people.zip"))
    fileURLs.push(context.session.formatFileDataURL("places.zip"))
    fileURLs.push(context.session.formatFileDataURL("things.zip"))
end if

' Dump CR-LF list of file URLs:
result = fileURLs.dump()

' Output file URLs as comma delimited list:
? crlf_to_comma(result)
%>