From the blog

Azure Storage and SFTP via CLI

keyboard

I had a need to stand up an SFTP server in Azure. I found a blog post on Microsoft Docs that used an ARM template to set this up (https://docs.microsoft.com/en-us/samples/azure-samples/sftp-creation-template/sftp-on-azure/).

The basic steps I needed to accomplish were:

  1. Create an Azure Storage Account
  2. Create a File Share on the Azure Storage Account
  3. Stand up a Container Instance of the atmoz/sftp image and point it to the File Share

Note: I wanted to ultimately stand up an Azure Function that responds to files being added but Files Shares do not currently communicate with Event Bus like Blob Storage.

Additionally, I wanted to use Azure CLI instead of an ARM template to stand up the infrastructure. Here is the PowerShell script that I came up with:

A note on the above script. It is a direct translation of the source ARM templates. One of the steps is to use a container to create a file share on the storage account. You will get an error if you try to run this directly in the CLI with no delay immediately after creating the storage account. My best guess is that there is a small delay needed between creating the storage account and creating a file share and the workaround was to spin up a container. You could also use a thread sleep to achieve the same since we are in PowerShell.