Welcome › Forums › General PowerShell Q&A › Invoke-WebRequest sometimes does not download the complete zip or msi file
- This topic has 1 reply, 2 voices, and was last updated 5 months ago by
Participant.
-
AuthorPosts
-
-
August 26, 2020 at 3:02 pm #252668
Hi,
I have external repository from where I need to download my installation files. They are in zip or msi format – for both I noticed that SOMETIMES (about 50%) it does not download them properly.
Invoke-WebRequest -Headers @{‘X-JFrog-Art-Api’=$API_KEY} “$COMPONENT/PowerShell_7_0_0.zip” -OutFile “$DOWNLOAD_PATH\PowerShell_7_0_0.zip”
Because of that my file is not useful, it’s invalid.
I know I can check it “checksum” and compare it with expected value:
(Get-FileHash -Algorithm SHA256 C:\Octopus\Applications\PowerShell_7_0_0.zip).Hash
But isn’t there some better way how I can overcome this? Maybe some built-in TimeOut or Retry for Invoke-WebRequest… or maybe to use some other method… I do not know…
But this is really a big issue which I suppose someone already encountered and resolved it..
I will appreciate very much your assistance. Thanks
-
August 27, 2020 at 11:06 am #252989
I’ve used the native .Net webclient in the past to download files. This following script will hopefully help;
PowerShell12345678910111213141516171819# set Download path$DOWNLOAD_PATH = "C:\Temp"# API Key$API_KEY = 'yourAPIkey'# URL to file$COMPONENT = "https://someurl.com/filestore/"# file to download$download_file = "PowerShell_7_0_0.zip"# set up the .net webclient$Wget = New-Object System.Net.WebClient# add headers$Wget.Headers["X-JFrog-Art-Api"] = $API_KEY# download the file$Wget.DownloadFile("$COMPONENT/$download_file" , "$DOWNLOAD_PATH\$download_file")
-
-
AuthorPosts
- The topic ‘Invoke-WebRequest sometimes does not download the complete zip or msi file’ is closed to new replies.