HOW TO download a list of files with a PowerShell script
If you use Windows Vista or higher, PowerShell comes along with it. So if you have to download a list of files, you can do that easily with this PowerShell script instead of installing any other tools (command-line or GUI)
To get a single file, you can use just this line of code:
(new-object System.Net.WebClient).DownloadFile('http://www.xyz.net/file.txt', 'C:\tmp\file.txt')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell script to download a list of files that have a predictable number pattern | |
for ($i=1; $i -le 10; $i++) | |
{ | |
$startTime = (Get-Date) | |
# Download files that have the naming format File1.txt, File2.txt etc.. | |
(new-object System.Net.WebClient).DownloadFile("http://example/file$i.txt","C:\temp\file$i.txt") | |
$endTime = (Get-Date) | |
# Echo Time taken | |
"Time taken to download file$i : $(($endTime-$startTime).totalseconds) seconds" | |
} |
To get a single file, you can use just this line of code:
(new-object System.Net.WebClient).DownloadFile('http://www.xyz.net/file.txt', 'C:\tmp\file.txt')
You can also use the PowerShell Invoke-WebRequest cmdlet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell script to download a list of files that have a predictable number pattern 1.jpg, 2.jpg etc.. | |
$baseUri = "https://somesite.com/files/" | |
for ($i = 1; $i -lt 9; $i++) { | |
{ | |
$f = $baseUri + $i + ".jpg" | |
$Downloadpath = "C:\temp\" + $i + ".jpg" | |
Write-Output "Processing file: $f" | |
Invoke-WebRequest -Uri $f -Outfile $Downloadpath | |
} |
Comments
Post a Comment