Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.6.0+

Azure Files: Download with Entra OAuth and Backup Intent

See more Azure Cloud Storage Examples

Use a Storage-audience token saved by either authentication example, then stream a file through FileREST with x-ms-file-request-intent: backup. The identity needs file read permission and readFileBackupSemantics; Storage File Data Privileged Reader is the built-in read role for this use. This privileged access can bypass file/directory ACLs within the role's scope. Ordinary SMB Share Reader permissions alone are insufficient.

This is REST authorization, not SMB/Kerberos authentication. It applies to classic Azure file shares created through Microsoft.Storage, not Microsoft.FileShares resources. A 403 can indicate missing backup-semantics permission or account/network policy even when token acquisition succeeds. The token is not refreshed automatically; reacquire it before expiry.

First obtain the token with Entra client credentials or an Azure VM managed identity.

Uses direct Chilkat.Rest requests and Azure public-cloud endpoints with verified HTTPS. REST requests select service version 2026-04-06. Create local input/output directories before running. Account-key examples read account and access_key string fields from private qa_data/azure/storage.json; do not embed secrets in distributed applications. Entra examples explain their own configuration. Keep credentials, bearer tokens, SAS URLs and diagnostic dumps private. Shared Key is supported only where allowed by account policy; Entra authentication is preferred where available.

Transport success and HTTP status are checked separately. Writes are not automatically replayed after an uncertain response. IDs, ETags, continuation markers and file sizes are strings; counters and explicitly bounded offsets use int. No webhook or web server is required.

Microsoft reference.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loTextCompare
LOCAL loConfig
LOCAL lnSameText1
LOCAL loEndpoint
LOCAL lcResourcePath
LOCAL loRest
LOCAL loConnection
LOCAL loResult
LOCAL loSavedToken
LOCAL lnSameText2
LOCAL loExpiry
LOCAL loNow
LOCAL lcAccessToken
LOCAL loBearer
LOCAL loFiles
LOCAL loSink
LOCAL lnHttpStatus

lnSuccess = 0

*  StringBuilder compares text by value in every generated language.
loTextCompare = CreateObject('Chilkat.StringBuilder')
*  Assumes Chilkat is unlocked. See Global Unlock Sample.
lnSuccess = 0
loConfig = CreateObject('Chilkat.JsonObject')
loConfig.Strict = 1
lnSuccess = loConfig.LoadFile("qa_data/azure/storage.json")
IF (lnSuccess <> 1) THEN
    ? "Could not load private Azure configuration."
    RELEASE loTextCompare
    RELEASE loConfig
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loConfig.StringOf("account"))
lnSameText1 = loTextCompare.ContentsEqual("",1)
IF ((loConfig.JsonTypeOf("account") <> 1) OR (lnSameText1 = 1)) THEN
    ? "Supply the storage account name."
    RELEASE loTextCompare
    RELEASE loConfig
    CANCEL
ENDIF

loEndpoint = CreateObject('Chilkat.StringBuilder')
lnSuccess = loEndpoint.Append(loConfig.StringOf("account"))
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    CANCEL
ENDIF

lnSuccess = loEndpoint.Append(".file.core.windows.net")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    CANCEL
ENDIF

*  resourcePath is already URL-encoded. Encode each path segment once when adapting it.
*  Keep slash separators; names and paths are case-sensitive.
lcResourcePath = "/examples/files/example.bin"
loRest = CreateObject('Chilkat.Rest')
loRest.ConnectTimeoutMs = 20000
loRest.IdleTimeoutMs = 60000
loConnection = CreateObject('Chilkat.Socket')
loConnection.RequireSslCertVerify = 1
loConnection.MaxReadIdleMs = 60000
loConnection.MaxSendIdleMs = 60000
lnSuccess = loConnection.Connect(loEndpoint.GetAsString(),443,1,20000)
IF (lnSuccess <> 1) THEN
    ? "TLS connection failed; inspect diagnostics privately."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

*  Do not replay a write automatically after losing its response.
lnSuccess = loRest.UseConnection(loConnection,0)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    CANCEL
ENDIF

loResult = CreateObject('Chilkat.Xml')
loResult.Strict = 1
lnSuccess = loRest.AddHeader("x-ms-version","2026-04-06")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    CANCEL
ENDIF

*  Obtain this private file with either authentication example. Reacquire an expired token.
loSavedToken = CreateObject('Chilkat.JsonObject')
loSavedToken.Strict = 1
lnSuccess = loSavedToken.LoadFile("qa_data/azure/storage-token.json")
IF (lnSuccess <> 1) THEN
    ? "Could not load Storage token."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    CANCEL
ENDIF

loTextCompare.Clear()
loTextCompare.SetString(loSavedToken.StringOf("access_token"))
lnSameText2 = loTextCompare.ContentsEqual("",1)
IF ((loSavedToken.JsonTypeOf("access_token") <> 1) OR (lnSameText2 = 1)) THEN
    ? "Missing access token."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    CANCEL
ENDIF

loExpiry = CreateObject('Chilkat.CkDateTime')
loNow = CreateObject('Chilkat.CkDateTime')
lnSuccess = loExpiry.SetFromTimestamp(loSavedToken.StringOf("expires_at"))
IF (lnSuccess <> 1) THEN
    ? "Invalid token expiry."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    CANCEL
ENDIF

lnSuccess = loNow.SetFromCurrentSystemTime()
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    CANCEL
ENDIF

IF (loExpiry.DiffSeconds(loNow) < 60) THEN
    ? "Acquire a new Storage token before continuing."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    CANCEL
ENDIF

lcAccessToken = loSavedToken.StringOf("access_token")
loBearer = CreateObject('Chilkat.StringBuilder')
lnSuccess = loBearer.Append("Bearer ")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loBearer.Append(lcAccessToken)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("Authorization",loBearer.GetAsString())
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

lnSuccess = loRest.AddHeader("x-ms-file-request-intent","backup")
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    CANCEL
ENDIF

loFiles = CreateObject('Chilkat.FileAccess')
IF (loFiles.FileExists("qa_output/azure-file.bin") = 1) THEN
    ? "Choose a new destination filename."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loFiles
    CANCEL
ENDIF

loSink = CreateObject('Chilkat.Stream')
loSink.SinkFile = "qa_output/azure-file.bin.part"
lnSuccess = loRest.SendReqNoBody("GET",lcResourcePath)
IF (lnSuccess <> 1) THEN
    ? "Could not prepare the request."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loFiles
    RELEASE loSink
    CANCEL
ENDIF

lnHttpStatus = loRest.ReadResponseHeader()
IF (lnHttpStatus < 0) THEN
    ? "Could not read response headers."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loFiles
    RELEASE loSink
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "HTTP status: " + STR(loRest.ResponseStatusCode)
    ? "Azure error code: " + loRest.ResponseHdrByName("x-ms-error-code")
    ? "Request ID: " + loRest.ResponseHdrByName("x-ms-request-id")
    *  Inspect any error body privately; do not log credentials, SAS URLs or payloads.
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loFiles
    RELEASE loSink
    CANCEL
ENDIF

lnSuccess = loRest.ReadRespBodyStream(loSink,0)
IF (lnSuccess <> 1) THEN
    ? "Transfer incomplete; the .part file is not a completed download."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loFiles
    RELEASE loSink
    CANCEL
ENDIF

lnSuccess = loFiles.FileRename("qa_output/azure-file.bin.part","qa_output/azure-file.bin")
IF (lnSuccess <> 1) THEN
    ? "Could not publish downloaded file."
    RELEASE loTextCompare
    RELEASE loConfig
    RELEASE loEndpoint
    RELEASE loRest
    RELEASE loConnection
    RELEASE loResult
    RELEASE loSavedToken
    RELEASE loExpiry
    RELEASE loNow
    RELEASE loBearer
    RELEASE loFiles
    RELEASE loSink
    CANCEL
ENDIF

? "File downloaded using Entra authorization."

RELEASE loTextCompare
RELEASE loConfig
RELEASE loEndpoint
RELEASE loRest
RELEASE loConnection
RELEASE loResult
RELEASE loSavedToken
RELEASE loExpiry
RELEASE loNow
RELEASE loBearer
RELEASE loFiles
RELEASE loSink