Download File through proxy server
-
Tuesday, June 19, 2012 6:17 AM
Hello !
I try to download file from site to my hardisk by PowerShell script through non-MS proxy with domain autorization.
$source = "http://mysite.ru/file.txt" $dest = "c:\file.txt" $WebClient = New-Object System.Net.WebClient $WebProxy = New-Object System.Net.WebProxy("http://proxyserver:port",$true) $WebProxy.Credentials = New-Object Net.NetworkCredential("user","password","domain.local") $WebClient.Proxy = $WebProxy $WebClient.DownloadFile($source,$dest)But, when I start this script, I get the error: The request failed with HTTP status 407: Proxy Authentication Required.
I read the System.Net.WebClient reference and found that Proxy property have a type IWebProxy. But when I try $WebClient = New-Object System.Net.IWebProxy("http://proxyserver:port",$true), I get the message that PowerShell can't find constructor of System.Net.IWebProxy.
How can I do it right ?
Andy Mishechkin
All Replies
-
Tuesday, June 19, 2012 7:15 AM
Hi Andy,
Your script works for me. Only when I put wrong crentials I get your erros.
PS. I have too non-MS proxy and I put only user and password witout domain:$WebProxy.Credentials = New-Object Net.NetworkCredential("user","password","") -
Tuesday, June 19, 2012 10:07 AMPossibly I get the error because my proxy (Squid 3.1.16) using the Kerberos for autorization
Andy Mishechkin
-
Thursday, June 21, 2012 11:19 AM
The problem is solved:
$source = "http://site.com/file.txt" $dest = "C:\file.txt" $WebClient = New-Object System.Net.WebClient $WebProxy = New-Object System.Net.WebProxy("http://myproxy.com:1111",$true) $Credentials = New-Object Net.NetworkCredential("user,"","domain.local") $Credentials = $Credentials.GetCredential("http://myproxy.com","1111", "KERBEROS"); $WebProxy.Credentials = $Credentials $WebClient.Proxy = $WebProxy $WebClient.DownloadFile($source,$dest)Andy Mishechkin
- Marked As Answer by Andy Mishechkin Thursday, June 21, 2012 11:19 AM

