通过 powershell 运行 curl - 如何构造参数? [英] Running curl via powershell - how to construct arguments?

查看:53
本文介绍了通过 powershell 运行 curl - 如何构造参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行 curl 以在我的脚本中上传文件,使用批处理很痛苦,因为我需要进行字符串操作等,所以我转向了 powershell.

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.

但是我似乎无法让 powershell 执行 Curl:

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

结果:

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 在我的路径中.

Curl.exe is in my PATH.

推荐答案

在 PowerShell 中 curlInvoke-WebRequest cmdlet 的内置别名.并且别名在命令解析中具有优先权.要更具体地解决您的问题,请使用 curl.exe 而不是 curl,因此命令不会解析为别名.或者您可以删除别名 Remove-Item alias:curl,但由于它是内置别名,您必须将此命令放入您的配置文件中,或在每个会话中调用它.

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.

如果您不确定 PowerShell 如何解析您的命令,那么您可以使用 Get-Command cmdlet:

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

Get-Command curl
Get-Command curl.exe

这篇关于通过 powershell 运行 curl - 如何构造参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆