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?
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 )
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With