Background

I have an azure web applicaiton that has a dependency on other assets that I dont realise that I need them until, I well, need them.

I initially tried to ftp the files on to the server and have the web app access them from there, but alas this did not work. The wwwroot that you see via Filezilla is not the actual folder that is running inside a container.

After fighting with ftp, I found that using the Azure CLI and scp (secure copy) worked well.

Details

  1. Assumes that you have the Azure CLI installed

On a Mac you can install this easily using brew.

  brew update && brew install azure-cli

  1. Login to your Azure subscription

From a terminal…

  az login

This pops up a browser window and gets you to authenticate yourself.

Once you have authenitcated your terminal will output some json, which will include your subscription Id that you will need shortly (you can also get this from the App Service overview on the portal.azure.com).

  ...
{
  "cloudName": "AzureCloud",
  "homeTenantId": "cf8545d0-6b50-4bd9-b11f-f5c09366ffaa",
  "id": "7d5b0bc4-5b0b-4b0b-b0bf-1b0b3b0b5b0b",                 <== this is the one you want
  "isDefault": false,
  "managedByTenants": [],
  "name": "Microsoft Partner Network",
  "state": "Enabled",
  "tenantId": "6f5ffbae-82c3-44e1-9a5c-9a510b679f5b",
  "user": {
    "name": "bob@bobber.com",
    "type": "user"
  }
},
...

  1. Create a secure connection to the app server
      az webapp create-remote-connection --subscription <subscription-id> -g <resource-group-name> -n <app-name> &

eg.

  az webapp create-remote-connection --subscription 7d5b0bc4-5b0b-4b0b-b0bf-1b0b3b0b5b0b -g marcs-rg -n marcs-app &

This runs in the background and establishes an ssh tunnel to your azure app referenced above. Once established…

  | => Verifying if app is running....
  App is running. Trying to establish tunnel connection...
  Opening tunnel on addr: 127.0.0.1
  Opening tunnel on port: 65084
  SSH is available { username: root, password: Docker! }     <== You'll need this password later
  Ctrl + C to close

You will need to take note of the port that your connection is running on. 65084 from output above.

  1. You can now copy any files that you need up to app

It is recommended that you copy any content files to the /home/data directory which is mounted to the app container. You can copy the files up using the scp (secure copy) command.

  scp -P [port generated from the previous command] myFile.dat root@127.0.0.1:/home/data/

eg. I keep all of the files I am needing to transfer in the single directory and sync them all up using…

  scp -P 65084 *.dat root@127.0.0.1:./home/data/

You will be prompted to enter the password, which was output earlier and I imagine is Docker!

Wrapping up

This works well for me and can be pulled together into a script which is nice. It also means that I’m able to stay in the terminal and not have to faff about with an ftp application.

Ideally, the web app would access these files from Azure Blob Storage and that will come. For the time being though this isnt too painful.