Powershell Curl.exe to download a file from a variable link

Luke P 1 Reputation point
2022-06-26T04:58:53.497+00:00

Hello,
I am trying to use

curl.exe -o selenium-webdriver.nupkg https://www.nuget.org/api/v2/package/Selenium.WebDriver

In order to download the file selenium.webdriver.4.3.0.nupkg to my pc, and this will be used in automation. However downloading it with just /Selenium.WebDriver rather than /selenium.webdriver.4.3.0.nupkg causes a corrupted file, presumably because it is not specified exactly.

When entering https://www.nuget.org/api/v2/package/Selenium.WebDriver into my search bar it downloads the nupkg file without issue.

I have to use curl.exe as my companies proxy blocks wget and Invoke-Webrequest.
Am I doing something wrong?

Thanks

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,621 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 35,416 Reputation points
    2022-06-26T13:49:04.017+00:00

    The "corrupt file" is actually an "object moved" link. Add the -L switch.

    -L, --location Follow redirects

    curl.exe -L -o selenium-webdriver.nupkg https://www.nuget.org/api/v2/package/Selenium.WebDriver  
    
    1 person found this answer helpful.
    0 comments No comments

  2. Limitless Technology 39,796 Reputation points
    2022-06-28T07:32:22.717+00:00

    Hello LukeP

    This may seem a Curl issue, since the http request is successful (no file corruption). I would suggest to open a Curl ticket through the "Report a bug" in their website.

    On the other hand, I would help if you could manage to get an exception on your company to use Invoke-Webrequest in case the usage is required.

    ---------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.