Samples for using the Azure App Service Kudu REST API to programmatically manage files in your site


Information about the Kudu REST API is found here:

https://github.com/projectkudu/kudu/wiki/REST-API

The VFS API section contains examples for programmatically managing files and directories in the App Service.

 

Here is an example (written in PowerShell) for listing the files and folders in the wwwroot folder.

$username = “`$websitename”;

$password = “password”;

<# This is the password from the msdeploySite credentials in the publish profile.

You can get the publish profile by going to the Overview blade on your App Service, clicking …More at the top of the blade, and then clicking Get publish profile.

#>

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((“{0}:{1}” -f $username,$password)))

$userAgent = “powershell/1.0”;

$apiUrl = “https://websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/“;

Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=(“Basic {0}” -f $base64AuthInfo)} -UserAgent $userAgent -Method GET -ContentType “application/json”;

 

Here is an example that puts a local file from your machine into the App Service file system:

$filePath = “c:\temp\text.txt”;

$apiUrl = “https://websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/test.txt“;

Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=(“Basic {0}” -f $base64AuthInfo)} -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType “multipart/form-data”;

 


Comments (0)

Skip to main content