Background


I discovered a website that serves its files from an Azure Storage blob container. I'm curious about the contents of this directory. However, Azure Storage Accounts, when used as web servers, do not support "directory browsing." Is it still possible to list all the files in the directory? Let's see.

Solution


To list all the files in a public Azure Storage Blob container, we can use send HTTP requests to the Azure Storage REST API, or use Azure CLI and Azure SDK. Let's begin with the most easy way. 

REST API

When you have the storage container URL, just append ?restype=container&comp=list to the end, you will get all the files. Since the container is public, no authentication is required.

Example

Access https://demo996.blob.core.windows.net/goodstuff from browser, you get nothing:

Access https://demo996.blob.core.windows.net/goodstuff?restype=container&comp=list from browser, you can get everything in XML format:

You can see more REST API usages from Microsoft docs.

Azure CLI

We can do the same operation from Azure CLI:

az storage blob list --account-name demo996 --container-name goodstuff --output table

Azure SDK

Example Python code:

pip install azure-storage-blob
from azure.storage.blob import BlobServiceClient

account_url = "https://demo996.blob.core.windows.net"
container_name = "goodstuff"

blob_service_client = BlobServiceClient(account_url=account_url)
container_client = blob_service_client.get_container_client(container_name)

blobs_list = container_client.list_blobs()

for blob in blobs_list:
    print(blob.name)