|
|
@ -40,22 +40,39 @@ Else {
|
|
|
|
Fail-Json $result "missing required argument: dest"
|
|
|
|
Fail-Json $result "missing required argument: dest"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$skip_certificate_validation = Get-Attr $params "skip_certificate_validation" $false | ConvertTo-Bool
|
|
|
|
|
|
|
|
$username = Get-Attr $params "username"
|
|
|
|
|
|
|
|
$password = Get-Attr $params "password"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($skip_certificate_validation){
|
|
|
|
|
|
|
|
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$force = Get-Attr -obj $params -name "force" "yes" | ConvertTo-Bool
|
|
|
|
$force = Get-Attr -obj $params -name "force" "yes" | ConvertTo-Bool
|
|
|
|
|
|
|
|
|
|
|
|
If ($force -or -not (Test-Path $dest)) {
|
|
|
|
If ($force -or -not (Test-Path $dest)) {
|
|
|
|
$client = New-Object System.Net.WebClient
|
|
|
|
$client = New-Object System.Net.WebClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($username -and $password){
|
|
|
|
|
|
|
|
$client.Credentials = New-Object System.Net.NetworkCredential($username, $password)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Try {
|
|
|
|
Try {
|
|
|
|
$client.DownloadFile($url, $dest)
|
|
|
|
$client.DownloadFile($url, $dest)
|
|
|
|
$result.changed = $true
|
|
|
|
$result.changed = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch {
|
|
|
|
Catch {
|
|
|
|
Fail-Json $result "Error downloading $url to $dest"
|
|
|
|
Fail-Json $result "Error downloading $url to $dest $($_.Exception.Message)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Else {
|
|
|
|
Else {
|
|
|
|
Try {
|
|
|
|
Try {
|
|
|
|
$webRequest = [System.Net.HttpWebRequest]::Create($url)
|
|
|
|
$webRequest = [System.Net.HttpWebRequest]::Create($url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($username -and $password){
|
|
|
|
|
|
|
|
$webRequest.Credentials = New-Object System.Net.NetworkCredential($username, $password)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$webRequest.IfModifiedSince = ([System.IO.FileInfo]$dest).LastWriteTime
|
|
|
|
$webRequest.IfModifiedSince = ([System.IO.FileInfo]$dest).LastWriteTime
|
|
|
|
$webRequest.Method = "GET"
|
|
|
|
$webRequest.Method = "GET"
|
|
|
|
[System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse()
|
|
|
|
[System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse()
|
|
|
@ -68,11 +85,11 @@ Else {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch [System.Net.WebException] {
|
|
|
|
Catch [System.Net.WebException] {
|
|
|
|
If ($_.Exception.Response.StatusCode -ne [System.Net.HttpStatusCode]::NotModified) {
|
|
|
|
If ($_.Exception.Response.StatusCode -ne [System.Net.HttpStatusCode]::NotModified) {
|
|
|
|
Fail-Json $result "Error downloading $url to $dest"
|
|
|
|
Fail-Json $result "Error downloading $url to $dest $($_.Exception.Message)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch {
|
|
|
|
Catch {
|
|
|
|
Fail-Json $result "Error downloading $url to $dest"
|
|
|
|
Fail-Json $result "Error downloading $url to $dest $($_.Exception.Message)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|