Monthly Archives: January 2016

Upload large files to Azure file share

This tutorial will describe howto upload large files to Azure file share using azCopy and PowerShell. First time I tried to upload large files to Azure I was a bit optimistic and tried to copy and paste my files directly through remote desktop. My files where database files with around 200gb of data using an internet connection with about 5mbit/s in upload speed. It did not work out very well and I had issues with timed out/aborted file transfers.  Then I tried to use plain PowerShell and Set-AzureStorageBlobContent to upload my files to an azure file share however it still timed out or got interrupted.

To solve this issue I used an azure file share, PowerShell and and azCopy to do the task. azCopy is a command line utility that lets you copy data to Azure Blob, File, and Table storage. Recent versions also supports to resume failed and interrupted uploads.

This tutorial assumes you already have a working Azure subscription and that you have configured Azure for use with PowerShell:

Before we can upload any files to Azure we will need to store them somewhere so go ahead and create an Azure file share.

Create Azure file share

azure create storage account

Do not choose any premium storage since it does not work as a file share. Choose a standard storage type. (Standard-RAGRS for example):

azure create storage account choose type

The file share can be used as a network drive on your virtual machine(s). When your file share is created select it and click connect to get the command to mount it as a network drive:

azure create storage account file share connect

If you click properties you will see the URL of the file share:

azure file share url

In order to connect to the file share you will need the access key which can be found on the main page of the storage account under access keys:

azure create storage account find keys

Keep the access key and the URL. It will be needed when we run our PowerShell script and azCopy later on.

Install azCopy

Download and install:

Run azCopy PowerShell script

azCopy will by default install to C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy. When transferring files azCopy will keep a journal in %LocalAppData%\Microsoft\Azure\AzCopy which can be used to resume failed file transfers.

Modify the script below to fit your needs:

$azCopyPath = "C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy"
Set-Location $azCopyPath

$accountName = "azcopydemoclassic"
$accountKey = "ABC123-YOUR-KEY-GOES-HERE"
$dest = ""

$filesToTransfer = 

foreach ($file in $filesToTransfer) {	
	$fileItem = Get-ChildItem $file
	$path = $fileItem.DirectoryName + "\"
	$fileName = $fileItem.Name
	Write-Host "Path: " $path -ForegroundColor Yellow
	Write-Host "Filename: " $fileName -ForegroundColor Yellow
	$transferResult = .\AzCopy.exe /Source:$path /Pattern:$fileName /Dest:$dest /destkey:$accountKey /Y	
	[int]$f = $transferResult[5].Split(":")[1].Trim()
	$azJournal = "$env:LocalAppData\Microsoft\Azure\AzCopy"
	while ($f -gt 0) {
		[int]$f = $transferResult[5].Split(":")[1].Trim()
		$transferResult = .\AzCopy.exe /Z:$azJournal /Y

Download script (azCopyToFileShare.ps1)