Downloading Azure Blob Storage with Azure CLI

This guide explains how to download blobs from Azure Blob Storage using the Azure Command-Line Interface (CLI).

Prerequisites

The az storage blob download Command

The primary command for downloading blobs is az storage blob download. It offers flexibility in specifying the blob and the destination for the download.

Basic Usage

To download a single blob to the current directory:

az storage blob download --container-name --name --file

Example: Downloading a specific blob

Let's say you have a blob named report.csv in a container named my-reports and you want to download it to your local machine as ~/downloads/report_final.csv.

az storage blob download --container-name my-reports --name report.csv --file ~/downloads/report_final.csv

Downloading to Standard Output

You can also download the blob content directly to standard output (stdout), which is useful for piping the output to other commands.

az storage blob download --container-name --name --file -

The - for the --file argument signifies stdout.

Downloading with a Specific Account Key

If you need to specify the storage account key instead of logging in via az login:

az storage blob download --account-name --account-key --container-name --name --file
Security Note: Avoid hardcoding account keys directly in scripts. Consider using Azure Key Vault or environment variables for better security practices.

Downloading from a Shared Access Signature (SAS) URL

If you have a SAS URL for the blob, you can use it to download the blob without needing account credentials directly.

az storage blob download --url --file

Advanced Options

Overwriting Existing Files

By default, the command will fail if the destination file already exists. You can use the --overwrite flag to allow overwriting.

az storage blob download --container-name --name --file --overwrite

Progress Bar

The Azure CLI typically shows progress for downloads. If you want to disable it or control its behavior, you can use the --progress parameter (though it's usually on by default).

Troubleshooting

For more detailed information and options, refer to the official Azure CLI documentation.