System.Net.WebClient in .bat problem with download zip file Powershell


  1. Posts : 11
    Windows 10 (1809)
       #1

    System.Net.WebClient in .bat problem with download zip file Powershell


    Hello, I'm preparing a .bat file that downloads few files. I encountered a problem with downloading a larger file. Perhaps it is not the size of the file but a specific link. Well, in the bat file I use the command:

    Code:
    powershell.exe -Command "(New-Object System.Net.WebClient).DownloadFile('http://download.gigabyte.eu/FileList/Driver/mb_driver_audio_realtek_9series.zip','c:\AutoInstalator_temp\mb_driver_audio_realtek_9series')"
    The file has been successfully downloaded but unfortunately has the extension (zip) (.zip) and instead of the content there is a file with the same name but no extension. After unpacking the second file, the content is finally there. But why?

    With smaller files of this type, I did not have any problems and I used the same formula.
    I also tried Start-BitsTransfer and it's the same problem. The only command that works correctly is Invoke-WebRequest but it is very slow.
    Do you know how to solve my problem?
      My Computer


  2. Posts : 14,046
    Windows 11 Pro X64 22H2 22621.1848
       #2

    It's a zip file so I would expect you would have to unzip it to get to the compressed contents.

    I downloaded it and when I unzip it, it creates a folder called 7727_PG439. Inside that folder is the actual driver files.
      My Computers


  3. Posts : 809
    Win10
       #3

    When I run the PS command I get a gzipped archive. It looks like the web server automatically enables HTTP compression even though it's only supposed to do it when the client requests it.

    Edit: It looks like the HTTP spec says that if the client doesn't specify an "Accept-Encoding" field then the server can choose whatever compression it wants.

    From a quick Google I don't see a quick fix for this but maybe someone with more WebClient experience can chime in on how to automatically decompress the data.

    From DownloadFile:
    Code:
    GET /FileList/Driver/mb_driver_audio_realtek_9series.zip HTTP/1.1 Host: download.gigabyte.eu
     Connection: Keep-Alive
     
    
     HTTP/1.1 200 OK
     Content-Type: application/x-zip-compressed
     Content-Length: 249491951
     Connection: keep-alive
     Date: Thu, 07 Feb 2019 06:19:55 GMT
     Last-Modified: Fri, 25 Jan 2019 12:05:11 GMT
     ETag: "4f3f257bb6aabcbd28b03d4c426b8a47-24"
     x-amz-meta-cb-realsize: 250605594
     Content-Encoding: gzip
    From Firefox:
    Code:
    GET /FileList/Driver/mb_driver_audio_realtek_9series.zip HTTP/1.1 Host: download.gigabyte.eu
     User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
     Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
     Accept-Language: en-US,en;q=0.5
     Accept-Encoding: gzip, deflate
     Connection: keep-alive
     Upgrade-Insecure-Requests: 1
     
    
     HTTP/1.1 200 OK
     Content-Type: application/x-zip-compressed
     Content-Length: 249491951
     Connection: keep-alive
     Date: Tue, 05 Feb 2019 22:43:22 GMT
     Last-Modified: Fri, 25 Jan 2019 12:05:11 GMT
     ETag: "4f3f257bb6aabcbd28b03d4c426b8a47-24"
     x-amz-meta-cb-realsize: 250605594
     Content-Encoding: gzip
    Last edited by PolarNettles; 07 Feb 2019 at 02:17.
      My Computer


  4. Posts : 11
    Windows 10 (1809)
    Thread Starter
       #4

    PolarNettles said:
    When I run the PS command I get a gzipped archive. It looks like the web server automatically enables HTTP compression even though it's only supposed to do it when the client requests it.

    Edit: It looks like the HTTP spec says that if the client doesn't specify an "Accept-Encoding" field then the server can choose whatever compression it wants.

    From a quick Google I don't see a quick fix for this but maybe someone with more WebClient experience can chime in on how to automatically decompress the data.

    From DownloadFile:
    Code:
    GET /FileList/Driver/mb_driver_audio_realtek_9series.zip HTTP/1.1 Host: download.gigabyte.eu
     Connection: Keep-Alive
     
    
     HTTP/1.1 200 OK
     Content-Type: application/x-zip-compressed
     Content-Length: 249491951
     Connection: keep-alive
     Date: Thu, 07 Feb 2019 06:19:55 GMT
     Last-Modified: Fri, 25 Jan 2019 12:05:11 GMT
     ETag: "4f3f257bb6aabcbd28b03d4c426b8a47-24"
     x-amz-meta-cb-realsize: 250605594
     Content-Encoding: gzip
    From Firefox:
    Code:
    GET /FileList/Driver/mb_driver_audio_realtek_9series.zip HTTP/1.1 Host: download.gigabyte.eu
     User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
     Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
     Accept-Language: en-US,en;q=0.5
     Accept-Encoding: gzip, deflate
     Connection: keep-alive
     Upgrade-Insecure-Requests: 1
     
    
     HTTP/1.1 200 OK
     Content-Type: application/x-zip-compressed
     Content-Length: 249491951
     Connection: keep-alive
     Date: Tue, 05 Feb 2019 22:43:22 GMT
     Last-Modified: Fri, 25 Jan 2019 12:05:11 GMT
     ETag: "4f3f257bb6aabcbd28b03d4c426b8a47-24"
     x-amz-meta-cb-realsize: 250605594
     Content-Encoding: gzip
    Yep and this is a problem ;/ somebody know how to resolve this?
      My Computer


  5. Posts : 3,453
       #5

    This is a simpler way...

    Code:
    Invoke-WebRequest -Uri 'http://download.gigabyte.eu/FileList/Driver/mb_driver_audio_realtek_9series.zip' -OutFile 'test.zip'
    System.Net.WebClient in .bat problem with download zip file Powershell-screenshot-2019-02-07-19-12-18.png

    (This is on Ubuntu but should work on Windows likewise)
      My Computer


  6. Posts : 11
    Windows 10 (1809)
    Thread Starter
       #6

    Superfly said:
    This is a simpler way...

    Code:
    Invoke-WebRequest -Uri 'http://download.gigabyte.eu/FileList/Driver/mb_driver_audio_realtek_9series.zip' -OutFile 'test.zip'
    System.Net.WebClient in .bat problem with download zip file Powershell-screenshot-2019-02-07-19-12-18.png

    (This is on Ubuntu but should work on Windows likewise)
    As I said earlier, "Invoke-WebRequest" works correctly but is 5x slower. What significantly extends the download time with a few larger files.
      My Computer


  7. Posts : 809
    Win10
       #7

    The OP indicated that Invoke-Webrequest is much slower than WebClient.DownloadFile, and that is my experience as well.

    But according to Progress bar can significantly impact cmdlet performance · Issue #2138 · PowerShell/PowerShell · GitHub if you turn off the progress bar it goes normal speed. I tried it and it worked for me.

    Code:
    PS C:\temp> $start = Get-Date; (New-Object System.Net.WebClient).DownloadFile('http://download.gigabyte.eu/FileList/Driver/mb_driver_audio_realtek_9series.zip','c:\temp\mb_driver_audio_realtek_9series.zip'); New-TimeSpan -Start $start
    
    TotalSeconds      : 8.9171472
    
    
    
    PS C:\temp> $start = Get-Date; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri 'http://download.gigabyte.eu/FileList/Driver/mb_driver_audio_realtek_9series.zip' -Outfile 'c:\temp\mb_driver_audio_realtek_9series.zip' -UseBasicParsing; New-TimeSpan -Start $start
    
    TotalSeconds      : 8.9849527
      My Computer


  8. Posts : 3,453
       #8

    OIC, sorry didn't read the whole OP... I have always Invoked to get progress but good point about the write progress overhead
      My Computer


  9. Posts : 11
    Windows 10 (1809)
    Thread Starter
       #9

    PolarNettles said:
    The OP indicated that Invoke-Webrequest is much slower than WebClient.DownloadFile, and that is my experience as well.

    But according to Progress bar can significantly impact cmdlet performance · Issue #2138 · PowerShell/PowerShell · GitHub if you turn off the progress bar it goes normal speed. I tried it and it worked for me.

    Code:
    PS C:\temp> $start = Get-Date; (New-Object System.Net.WebClient).DownloadFile('http://download.gigabyte.eu/FileList/Driver/mb_driver_audio_realtek_9series.zip','c:\temp\mb_driver_audio_realtek_9series.zip'); New-TimeSpan -Start $start
    
    TotalSeconds      : 8.9171472
    
    
    
    PS C:\temp> $start = Get-Date; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri 'http://download.gigabyte.eu/FileList/Driver/mb_driver_audio_realtek_9series.zip' -Outfile 'c:\temp\mb_driver_audio_realtek_9series.zip' -UseBasicParsing; New-TimeSpan -Start $start
    
    TotalSeconds      : 8.9849527
    I don't need a progress bar. Thank you very much :) Working well
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 04:16.
Find Us




Windows 10 Forums