29

I'm trying to run curl to upload a file in my script, using batch was painful because I need to do string manipulation etc so I turned to powershell.

However I can't seem to get powershell to execute Curl:

$hash = "test"
$fileToUpload = "hello world.txt"
$user = "user"
$password = "passy"
curl --ftp-create-dirs -T $fileToUpload -u ${user}:${pass} ftp://example.com/$hash/$fileToUpload

This results in:

Invoke-WebRequest : Parameter cannot be processed because the parameter name 'T' is ambiguous. Possible matches include: 
-TimeoutSec -TransferEncoding.
At line:5 char:24
+ curl --ftp-create-dirs -T $fileToUpload -u ${user}:${pass} ftp://example.com/$ha ...
+                        ~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Curl.exe is in my PATH.

6
  • 22
    curl -> curl.exe Commented Jun 12, 2015 at 16:01
  • huh.. why does that work? Commented Jun 12, 2015 at 16:09
  • 2
    To add to what @PetSerAl said - when calling "curl", it is mapped as an alias to the Invoike-WebRequest cmdlet. Use "curl.exe" to call the curl executable. You can confirm this with: Get-Alias -name curl Commented Jun 12, 2015 at 16:09
  • Ah I didn't know it was a built in thing, if someone adds an answer I'll accept Commented Jun 12, 2015 at 16:12
  • 2
    @PetSerAl should get the accepted answer. Commented Jun 12, 2015 at 16:12

1 Answer 1

60

In PowerShell curl is a built in alias to Invoke-WebRequest cmdlet. And aliases have priority in command resolution. To solve your problem you have more specifically, use curl.exe instead of curl, so command not resolved to alias. Or you can remove alias Remove-Item alias:curl, but as it is build in alias you have to put this command in your profile, or invoke it in every session.

If you are not sure how PowerShell resolve your command, then you can use Get-Command cmdlet:

Get-Command curl
Get-Command curl.exe
Sign up to request clarification or add additional context in comments.

6 Comments

You can also check if an alias exists for a given command name by running Get-Alias -Name yourcommand.
@AnsgarWiechers You mean -Definition? Get-Alias -Definition Invoke-WebRequest
I meant -Name: Get-Alias -Name curl. I probably should've said "to check if for a given command name an alias with the same name exists".
Thank you...In my case using curl.exe instead of curl, solved the problem.
correct answer! thanks. .exe extension such a annoying thing when using powershell.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.