com pftt2: Make download_files.ps1 more robust.: bin/download_files.ps1

[email protected] (Christoph Michael Becker)
Newsgroups php.qa
Message-ID <[email protected]>
Commit:    fea34403b052f966fe795268d1e8d28b27c50499
Author:    Dale Hirt <[email protected]>         Thu, 14 Nov 2019 10:39:53 -0800
Committer: Christoph M. Becker <[email protected]>      Fri, 15 Nov 2019 09:56:44 +0100
Parents:   547ad0e532320f47eaecb432164422d6f6d9b1e3
Branches:  master

Link:       http://git.php.net/?p=pftt2.git;a=commitdiff;h=fea34403b052f966fe795268d1e8d28b27c50499

Log:
Make download_files.ps1 more robust.

Changed paths:
  M  bin/download_files.ps1


Diff:
diff --git a/bin/download_files.ps1 b/bin/download_files.ps1
index 0622e437..4bce1b01 100644
--- a/bin/download_files.ps1
+++ b/bin/download_files.ps1
@@ -1,11 +1,25 @@
-Param([string]$url, [string]$path, [string]$file_name)
+[cmdletbinding(SupportsShouldProcess=$true)]
+Param(
+	[Parameter(Mandatory)]
+	[string]$url, 
+	
+	[Parameter(Mandatory)]
+	[string]$path, 
+	
+	[Parameter(Mandatory)]
+	[string]$file_name
+)
 
 If ($url -eq "" -or $path -eq "" -or $file_name -eq "") {
 	Write-Output "User error: Must specifiy url, save path and file name"
 	Write-Output "download_file <url> <path to dir> <desired file name>"
 }
 
-Import-Module BitsTransfer
-
-Write-Host "Downloading" $file_name"..." -ForegroundColor Green
-	Start-BitsTransfer -Source $url -Destination $path
\ No newline at end of file
+$fullPath = join-path $path $file_name
+Write-Host "Downloading $($url) to $($file_name)..." -ForegroundColor Green
+if ($PSCmdlet.ShouldProcess($fullPath, "Download $url")) {
+	[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls,Tls11,Tls12'	
+	$wc = New-Object System.Net.WebClient
+	$wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
+	$wc.DownloadFile($url, $fullPath)
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.