-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathWebAppFiles.ps1
93 lines (70 loc) · 2.73 KB
/
WebAppFiles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function Copy-FileToWebApp
{
param(
[Parameter(Mandatory)]
[String]$ResourceGroupName,
[Parameter(Mandatory)]
[String]$WebAppName,
[Parameter(Mandatory)]
[String]$File,
[Parameter(Mandatory)]
[String]$Destination,
[Parameter(Mandatory=$false)]
[System.Object]$PublishingCredentials
)
if ([String]::IsNullOrEmpty($PublishingCredentials)) {
$PublishingCredentials = $(Get-WebAppPublishingCredentials -ResourceGroupName $ResourceGroupName -WebAppName $WebAppName)
}
$webclient = New-Object -TypeName System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($PublishingCredentials.username,$PublishingCredentials.password)
$uri = New-Object System.Uri($PublishingCredentials.url + "/$Destination")
$webclient.UploadFile($uri, $(Get-ChildItem $File).FullName)
$webclient.Dispose()
return $PublishingCredentials
}
function Create-WebAppDirectory {
param(
[Parameter(Mandatory=$true)]
[string]$Directory,
[Parameter(Mandatory)]
[String]$ResourceGroupName,
[Parameter(Mandatory)]
[String]$WebAppName,
[Parameter(Mandatory=$false)]
[System.Object]$PublishingCredentials
)
if ([String]::IsNullOrEmpty($PublishingCredentials)) {
$PublishingCredentials = $(Get-WebAppPublishingCredentials -ResourceGroupName $ResourceGroupName -WebAppName $WebAppName)
}
$uri = New-Object System.Uri($PublishingCredentials.url + "/$Directory")
try {
$ftprequest = [System.Net.FtpWebRequest]::Create($uri);
$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::MakeDirectory
$ftprequest.UseBinary = $true
$ftprequest.Credentials = New-Object System.Net.NetworkCredential($PublishingCredentials.username,$PublishingCredentials.password)
$response = $ftprequest.GetResponse();
$response.close();
}
catch
{
Write-Verbose "Folder not created"
}
}
function Get-WebAppPublishingCredentials
{
param(
[Parameter(Mandatory)]
[String]$ResourceGroupName,
[Parameter(Mandatory)]
[String]$WebAppName
)
$xml = [xml](Get-AzureRmWebAppPublishingProfile -Name $WebAppName -ResourceGroupName $ResourceGroupName)
$username = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userName").value
$password = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@userPWD").value
$url = $xml.SelectNodes("//publishProfile[@publishMethod=`"FTP`"]/@publishUrl").value
return @{
"username" = $username
"password" = $password
"url" = $url
}
}