How to use AzCopy to upload files from your PC to your Azure Storage account.

How to use AzCopy to upload files from your PC to your Azure Storage account.

Table of contents

No heading

No headings in the article.

Introduction

AzCopy is a command-line tool that can be used to copy data to or from Azure Blob storage. It is a powerful tool that can be used to automate data transfers, and it offers a variety of features to optimize performance.

In this post, I will show you how to use AzCopy to upload files from your PC to an Azure Storage account. We will cover the following topics:

  • Downloading and installing AzCopy

  • Authenticating to Azure Storage

    Uploading a directory to Azure Storage

Downloading and installing AzCopy

The first step is to download and install AzCopy. You can download AzCopy from the AzCopy website. Once you have downloaded AzCopy for the type of operating system eg. Windows,linux or macos, then you need to extract the zip file using winrar or the free windows extractor tool or any free zip extractor tool and save the executable file to a directory on your PC.

Here is mine as shown in the diagram below for windows PC.

Authenticating to Azure Storage

Before you can upload files to Azure Storage, you need to authenticate to your Azure Storage account. You can do this by providing your account name and key, or by using an Azure Active Directory (AD) account. In this diagram, I am using the Azure active directory.

I copied the address in the above diagram and then opened the command prompt as shown in the diagram below.

Then typed: cd which stands for 'change directory' and then pasted the address I copied as text then pressed enter key and used the command dir to see the files inside the folder as shown in the diagram below to be sure it corresponds with the location I copied address as text.

the command to check the status of your authentication on your PC is to first azcopy login status in this diagram it is still active, but I have to still authenticate for demonstration purposes.

To authenticate, I used the azcopy login command.

For example, to authenticate with an Azure AD account, you need to use the azcopy login command with the -tenant-id. you would use the following command:

azcopy login –tenant-id (tenant-id on your Azure AD account)

I have to go get the tenant-id as shown in the following diagrams below

I copied 2 into a browser as shown below then entered 3 as the code.

then here in the diagram below, I selected the email that i am using with the Azure portal.

Then followed the next diagram below I just click continue

Click on continue

Then in the diagram above this means successful so just follow the instructions on the screen and exit and close the tab and return to your command prompt there you will find login succeeded as shown in the diagram below then you can proceed to upload.

Uploading a directory to Azure Storage

Copy this location as text as shown in the diagram above as the source address to be used in the command prompt later in this post.

I ticked the required permissions that I need sas a token to allow which has been indicated in the diagram above.

Here in the above diagram, I copied the sas token.

I clicked on the container properties as indicated in the above diagram

Also shown above here is where I copied the URL, paste it in the command prompt as the destination URL and pasted sas after it.

You can also use the tab key for auto-completion eg. After pressing a press the tab to auto-complete the azcopy.exe then copy “paste the source address” then “paste the destination and sas token” –-recursive as shown in the diagram below.

azcopy.exe copy “source address” “destination address(sas token)” --recursive

Note: of the (")after both the source address and destination address with sas token as they are very important.

In the diagram above source address was c:\Users\elinathan\Pictures\Screenshots\Storage Account creation blog 1” whilst the destination address was "[reggiestorage37.blob.core.windows.net/reggi.. sas token immediately without spaces)" then a space then--recursive

This is the result of the command I entered it copied the folder including the files within it as shown in the above diagram.

These are the files inside the folder as shown in the above diagram.

Upload directory contents

Upload the contents of a directory by using the azcopy command. Use the wildcard symbol (*) to upload the contents without copying the containing directory itself, --recursive parameter.

azcopy.exe copy “C:\Users\elinathan\Pictures\Screenshots\Copy from one storage account to another\*” “[mystorageaccount.blob.core.windows.net/myco.. token)” --recursive

where the source address is “C:\Users\elinathan\Pictures\Screenshots\Copy from one storage account to another\*” and the destination address is "[reggiestorage37.blob.core.windows.net/reggi.. sas token immediately without spaces)" then a space then --recursive

Note: the difference with copying the whole directory is the (*) symbol here we will be copying the files in the directory without copying the folder itself.

as shown in the diagram above this indicates it worked as you can see the transfers: 4 and completed: 4 also final job status: completed

These are the files uploaded without the directory as shown in the diagram above.

In the above diagram, the files are shown in the storage explorer.

I hope this post was helpful, if you find it please like, comment and share.

For more information on AzCopy, please refer to the AzCopy documentation: https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-files