PowerShell的等价卷曲HTTP发布的文件传输 [英] Powershell equivalent of curl HTTP post for file transfer

查看:401
本文介绍了PowerShell的等价卷曲HTTP发布的文件传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前上传通过HTTP发布文件,像这样的电话:

I'm currently uploading a file via an HTTP post with a call like this:

curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n"

这工作得很好。不过,我居然有大约3000文件每日上传 - 在我的目录中的所有文件。我在想只是写了一个批处理文件,具有多个卷曲的命令,每个文件。但是,这会离开我,打开和关闭连接,一次为每个文件,用鼠标右键的开销?

This works fine. However, I actually have about 3000 files daily to upload - every file in my directory. I was thinking about just writing out a batch file that has multiple CURL commands, one for each file. But this would leave me with the overhead of opening and closing the connection once for each file, right?

所以,我考虑的Powershell。我不熟悉它,但我相信,我也许可以使用WebRequest的用于这一目的。

So, I considering Powershell. I'm not familiar with it, but I believe that I might be able to use WebRequest for this purpose.

这会是一个很好的选择吗?任何code样品指针?

Would this be a good option? Any code sample pointers?

在此先感谢。

推荐答案

在理论上以下...

curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n"

...可以通过使用 System.Net.WebClient.UploadFile 所取代。例如上传所有CSV文件在当前目录:

... could be replaced by using System.Net.WebClient.UploadFile. For example to upload all csv files in the current directory:

$wc = new-object System.Net.WebClient
ls *.csv | foreach { 
    $wc.UploadFile( 'http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n', $_.FullName )
}

这篇关于PowerShell的等价卷曲HTTP发布的文件传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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