Archive

Archive for the ‘Azure’ Category

Pushing Files to an Azure Web App Using PowerShell

The Point

I needed a way to push a file to my Azure Web App without having to add it to a Visual Studio project and then publish it to the website. Just an ad hoc thing to get a file (or a few files) out to that website for reference.  (Now feel free to skip ahead.)

Getting to… The Point

I was looking for something that was already done, but I found a post by Kaushal Kumar Panday who suggests to use the PublishSettings that can be downloaded from your Azure web app.  And then he goes on and uses FileZilla (which I don’t have on my work machine).  I wanted it to be a script that I could just run, so when I update a file I could just run the script and it would get pushed up to the site.  Maybe that script would notify the people that care about this file and they could download it, but that’s out of scope for this blog entry.

If you just want to start messing with things then you can scroll to the bottom of this post and download the PowerShell script and get started.

pushToAzure01

From the variables in the PublishSettings file copy and paste the URL (without the https://) into the $ftpUrl variable.  You will also have to split the publishUrl variable in the settings file into the first two variables above.  If the user name contains a dollar sign, that will need to be escaped with the back tick (`) so the name is not evaluated and you’re missing much of your user name because it’s blank.

pushToAzure02

The section above only is to let the scripter (person running the script) what the script is doing. (or is that scriptee?)

pushToAzure03

The FTP portion COULD be a static file, but I like to have everything contained within ONE file. I feel like it’s easier to manage that way. Of course it DID start out as a static file, but then I changed it so the “push” file script generates the FTP command file. This is where you could change things up and put multiple files (mput) or do other things out there on the server that FTP allows you to do.  This snippet doesn’t do much other than logon, change to the destination, upload the file, and then quit.

pushToAzure04

Once the file has been generated, then run the FTP command and connect to the website’s FTP server.

That’s IT!  Below is a link to the sample file out in one of my GitHub repositories.

pushFileToAzureWebApp.ps1 on GitHub  <<<<<<<<<<<<< If you’re skipping ahead. <<<<

I hope this helped.

Advertisements