Script throwing an error.. RRS feed

  • Question

  • hey this script keeps throwing an error goggled solutions but no luck. any suggestions?

    the error says "...the underlying connection was closed: An unexpected error occurred on a send... "$wc.Downloadstring($mainurl)"

    #<tr valign="top"><td><a href="../deadata/zipweekly/"></a> </td><td> 69.1 MB </td><td> 2013/11/11 </td><td align="center"> Weekly </td><td align="center"> 1512416</td>  
    $DebugPreference = "SilentlyContinue"
    $MainUrl = "https://XXX"
    $Username = "XXX"
    $Password = "XXX
    $wc = new-object System.Net.WebClient
    $wc.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
    $matches=[string] $ReportPage |select-string -pattern  "$ReportBlock" -AllMatches
    foreach($match in $matches.Matches) {	
       	$txt = ( ($match.Value  -replace "</A><br>", "`r`n") -replace  "<[^>]*?>","")
       	foreach($lines in $txt.Split("`r`n")){
          $line=$lines|select-string  -NotMatch -Pattern "To Parent|^$|&lt;dir&gt;"
          if ($line -ne $null){
    		 if (!(Test-Path "$ReportFolder\$line"))  { 
    		 	Try {	
               		$wc.DownloadFile("$ZipUrl/$line","$ReportFolder\$line" )
    	    	catch [System.Net.WebException]  {
    				echo "An error occurred: $ZipUrl/$line`r`n$ReportLocalDir\$_"
    				if ($_.Exception.InnerException) {"$($_.Exception.InnerException.Message)"}


    Friday, February 3, 2017 4:09 PM

All replies

  • Assuming that your hosting server correctly supports the download protocol you are using.

    Something like this should work:

    $source = ''
    $destination = "$env:programdata\notRoot\"
    $webClient = New-Object System.Net.WebClient
    $webClient.DownloadFile("$source", "$destination")
    Unblock-File $destination 

    Brian Ehlert
    Learn. Apply. Repeat.

    Friday, February 3, 2017 4:31 PM
  • thank you sir. what does your "env:programdata" in the $destination represent? "$env:programdata\notRoot\" 


    Friday, February 3, 2017 4:48 PM