The script at the first execution will dowload all the files, in the subsequent execution only new files will downloaded.
Change the ReportFolder and fill $Username and $Password correctly
cls
#<tr valign="top"><td><a href="../deadata/zipweekly/WA131111.zip">WA131111.zip</a> </td><td> 69.1 MB </td><td> 2013/11/11 </td><td align="center"> Weekly </td><td align="center"> 1512416</td>
$ReportFolder="c:\temp"
$DebugPreference = "SilentlyContinue"
$wc = new-object System.Net.WebClient
$userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;)"
$wc.Headers.Add("user-agent", $userAgent)
$MainUrl = "https://dea.ntis.gov/zips/weekly.html"
$ReportBlock=".*\.zip"
$ZipUrl="https://dea.ntis.gov/deadata/zipweekly"
#$usr=read-host
#$pwd=read-host -assecurestring
$Username = ""
$Password = ""
cd $ReportFolder
$ReportPage = $wc.DownloadString($MainUrl)
$matches=[string] $ReportPage |select-string -pattern "$ReportBlock" -AllMatches
$wc.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
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|^$|<dir>"
if ($line -ne $null){
if (!(Test-Path "$ReportFolder\$line")) {
Try {
$wc.DownloadFile("$ZipUrl/$line","$ReportLocalDir\$_" )
}
catch { echo "An error occurred: $line" }
}
}
}
}
Bye Gas