PowerShell equivalent of curl HTTP POST for file transfer
13,799
In theory the following...
curl --verbose --data-binary @C:\Projects\TestUploadFiles\TestFile1.csv "http://client.abc.com/submit?username=UserX&password=PasswordHere&app=test1&replacejob=TestNewJob&startjob=n"
It 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 )
}
Related videos on Youtube
Author by
Sylvia
Updated on June 04, 2022Comments
-
Sylvia over 1 year
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"
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?
So, I am considering PowerShell. I'm not familiar with it, but I believe that I might be able to use WebRequest for this purpose.
Would this be a good option? Any code sample pointers?