"Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
powershell
Solution
If you look at the MSDN documentation for the `DownloadFile` method, you'll notice that the second parameter is a filename, not a directory. So, if you re-define `$destination` to something like:
$destination = "c:\CHPACS\java-installer.zip"
then it should work.
Check secondly that the file that you're trying to download isn't open or being executed at the moment. This exception will be raised if the file is in use.
Problem
I am trying to setup to download need files to automate and install process. I keep getting errors ever time I run the script and I have changed it seven ways from sunday and it still gives me errors. The script is: ``` if (test-path $java_path) { Write-Output "Java already installed. Skipping script" exit 0 } else { $source = "http://our.server.com/java-installer.zip" $destination = "c:\CHPACS" $client = new-object System.Net.WebClient $client.DownloadFile($source, $destination) } ``` The error message that I am getting is ``` Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request." At C:\ps_script\testjava.ps1:41 char:31 + $client.DownloadFile <<<< ($source, $destination) + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : DotNetMethodException ``` Do I need to create a function to make this work properly? Thank you: