Forum Discussion
Upload Files to HTTP Server Using Webproxy
I have a fairly simple PowerShell script to upload a file (Filename.7z) from C:\Temp\ to a remote HTTP server (https://some-URL.com/Test/Imports/) using TLS1.2:-
$cred = New-Object System.Net.NetworkCredential("<username>",’<password>’)
$url = "https://some-URL.com/Test/Imports/Filename.7Z"
$input = "C:\Temp\Filename.7Z"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$wc = New-Object System.Net.WebClient
$wc.Credentials = $cred
$wc.UploadFile($url, "PUT", $input)
But what is the additional syntax needed if I want to specify a webproxy to use?
Many thanks
Have managed to figure this out for myself.
For anyone else that is interested it's pretty straightforward, just add the 2 lines below:-
$cred = New-Object System.Net.NetworkCredential("<username>",’<password>’)
$url = "https://some-URL.com/Test/Imports/Filename.7Z"
$input = "C:\Temp\Filename.7Z"$proxy = New-Object System.Net.WebProxy("webproxy.example.com:8080")
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$wc = New-Object System.Net.WebClient
$wc.Proxy = $proxy
$wc.Credentials = $cred
$wc.UploadFile($url, "PUT", $input)
1 Reply
- BriS72Copper Contributor
Have managed to figure this out for myself.
For anyone else that is interested it's pretty straightforward, just add the 2 lines below:-
$cred = New-Object System.Net.NetworkCredential("<username>",’<password>’)
$url = "https://some-URL.com/Test/Imports/Filename.7Z"
$input = "C:\Temp\Filename.7Z"$proxy = New-Object System.Net.WebProxy("webproxy.example.com:8080")
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$wc = New-Object System.Net.WebClient
$wc.Proxy = $proxy
$wc.Credentials = $cred
$wc.UploadFile($url, "PUT", $input)