|
|
|
@ -40,11 +40,23 @@ Else {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
If ($force -or -not (Test-Path $dest)) {
|
|
|
|
|
$client = New-Object System.Net.WebClient
|
|
|
|
|
|
|
|
|
|
if($username -and $password){
|
|
|
|
|
$client.Credentials = New-Object System.Net.NetworkCredential($username, $password)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Try {
|
|
|
|
|
$client.DownloadFile($url, $dest)
|
|
|
|
|
$result.changed = $true
|
|
|
|
@ -56,6 +68,11 @@ If ($force -or -not (Test-Path $dest)) {
|
|
|
|
|
Else {
|
|
|
|
|
Try {
|
|
|
|
|
$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.Method = "GET"
|
|
|
|
|
[System.Net.HttpWebResponse]$webResponse = $webRequest.GetResponse()
|
|
|
|
|