Commit 1f3c53af authored by Dustin Howett's avatar Dustin Howett

[Receive-WebFile] initial commit

parent 9de230a3
Function Receive-WebFile {
Param (
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)]
[string[]]$Uri
)
Begin {
$sources=@()
$destinations=@()
}
Process {
ForEach($u in $Uri) {
$resp = Invoke-WebRequest -Method:HEAD -Uri:$u -UseBasicParsing -ErrorAction:Continue
If($null -Ne $resp) {
$filename = Split-Path -Leaf -Path:$u
$cdisp = $resp.Headers["Content-Disposition"]
If(![string]::IsNullOrEmpty($cdisp)) {
$disps = $cdisp -Split ";\s*"
ForEach($d in $disps) {
$pair = $d -Split "\s*=\s*"
If($pair[0] -Eq "filename") {
$filename = $pair[1] -Replace "^`"|`"`$","" # Strip quotes at the beginning and end.
$filename = Split-Path -Leaf -Path:$filename
}
}
}
$sources += $u
$destinations += $filename
}
}
}
End {
If ($sources.Length -Gt 0) {
Start-BitsTransfer -Source:$sources -Destination:$destinations -TransferType:Download
} Else {
Write-Warning "No files to receive."
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment