Download new Azure Blob files to a Windows folder

A partner or vendor drops files into an Azure Blob container, but the software that needs them reads a folder on a Windows server. This guide shows how to pull the new files down with AzCopy, which SAS permissions to use, where such a job usually goes wrong, and when to use events instead. Each statement is checked against the Microsoft Learn pages listed at the end; we have not run the commands for you, so try them on a test folder first.

Step 1: Create a read-only SAS

A shared access signature (SAS) is a token you append to the container URL. Microsoft advises granting the least privileges possible and using a read-only SAS when you can. For a download job on a container, the permissions to choose are Read (r), which reads the content and properties of the blobs in the container, and List (l), which lists blobs.

Give the token an expiry that you will remember to renew. Microsoft notes that a stored access policy on the container lets you change or revoke a service SAS without regenerating the storage account keys, and that a container can have up to five stored access policies.

  • Choose Read and List only. Leave Write, Delete and Create off.
  • Set an expiry and put the renewal date in your calendar. An expired token stops the job.
  • Consider a stored access policy, so you can revoke the token if it leaks.
  • Treat the SAS URL like a password: do not paste it into shared scripts or tickets.

Step 2: Download with AzCopy

AzCopy v10 can synchronize a container to a local folder. Microsoft documents the syntax as azcopy sync, the container URL (with the SAS) as the source and the folder as the destination. For example: azcopy sync "https://mystorageaccount.blob.core.windows.net/mycontainer?<SAS>" "D:\Inbox" --recursive (replace the account, container and SAS with yours).

By default sync compares file names and last-modified times. Microsoft documents the --compare-hash flag to compare hashes instead, and --check-md5 to control how strictly the MD5 hash is checked on download (NoCheck, LogOnly, FailIfDifferent or FailIfDifferentOrMissing). Do not set --delete-destination unless you want AzCopy to remove local files that are no longer in the container.

Step 3: Know what a listing returns

The Blob service lists blobs in alphabetical order by name, not by date, and returns up to 5,000 items per response with a continuation token when there are more. Each blob has a Last-Modified property. A job that wants only new blobs therefore has to read the full listing and compare it with what it already has, which is what sync does for you.

Step 4: Schedule it and check the result

Run the command from a scheduled task. Then check the result, not just that the task started. Microsoft documents AzCopy exit codes: 0 means the job finished successfully, 1 means an error (look in the log), and 2 means a panic. AzCopy writes a log and a plan file for every job, by default under %USERPROFILE%\.azcopy on Windows.

AzCopy retries network errors, timeouts and server-busy errors up to 20 times, so the first error in a log can be harmless. Microsoft says to look at the errors near lines marked DOWNLOADFAILED (or UPLOADFAILED or COPYFAILED) instead. The commands azcopy jobs list and azcopy jobs show <job-id> list the jobs and their results, and azcopy jobs resume continues a failed one; resuming needs the SAS again because it is not stored.

  • Alert on any exit code other than 0.
  • Keep the logs somewhere your team will look, and clean old ones with azcopy jobs clean.
  • A 403 error is often a SAS problem: the start or expiry time, a missing permission, or the storage account firewall.
  • Download to a temporary folder and move finished files into the folder your software reads.

Step 5: If you need it faster

Blob Storage can push events through Azure Event Grid to Azure Functions, Logic Apps or your own HTTP listener when a blob is created, instead of polling. Microsoft notes that to react only to a block blob that is completely committed, you filter the Microsoft.Storage.BlobCreated event for the PutBlob, PutBlockList, CopyBlob or FlushWithClose calls. General purpose v1 storage accounts do not support Event Grid integration. These handlers run in Azure, so getting the file into a folder on your own server takes extra work.

Where BucketWatch fits

BucketWatch is coming soon and is meant to do this without a script: you paste a read-only SAS URL, pick a folder, and it downloads each new blob, remembers what it has, checks each download and alerts you when something fails. The Pro plan can also start your import program on each file. We have not set a launch date, and the manual steps above work today.

Sources

Coming soon: BucketWatch

New cloud files, downloaded to your folder. BucketWatch is a Windows service that watches an Azure Blob container or an Amazon S3 bucket and downloads new files to a folder you choose, local or on a network share. The Pro plan can then start your import program on each file. It alerts you when anything fails. It is for companies whose partner, lab or bank drops files into cloud storage but whose software only reads a folder.

About BucketWatchPrice comparison

Get BucketWatch first

Join the list and get 25% off your first purchase when it goes on sale. We email you a discount code on launch day. One code per person, for new customers.

One email when it launches (plus the discount code). No other mail, and you can say stop at any time. See our privacy policy.

An unhandled error has occurred. 🗙