Un esempio di come scaricare più file da un sito FTP tramite PowerShell

PowerShell

$ErrorActionPreference = "Stop"

$ftp = "ftp://www.address.com"
$user = "...userName..."
$pwd = "...password..."

#percorsi dei file da scaricare
$files = @(
    "/folder1/folder2/file1.mdb"
    ,"/folder3/file4.img"
)

#data di oggi
$dt = (Get-Date -Format yyyMMdd).ToString()

$wc = new-object System.Net.WebClient

#costruisco le credenziali di accesso al sito
$cc = New-Object System.Net.NetworkCredential($user, $pwd)
$wc.Credentials = $cc

$files | foreach {
  $url = $ftp + $_
  #ricavo il nome del file
  $name = [System.IO.Path]::GetFileName($url)
  #costruisco il nome del basato sul nome originale e la data di oggi
  #ed uso l'oggetto Get-Location per ricavare la directory corrente
  $file = (Get-Location).Path  + "\_" + $dt + "_" + $name

  write-host $url -ForegroundColor green
  write-host " save as $file ..." -ForeGroundColor green -NoNewLine

  #download e salvataggio del file
  $wc.DownloadFile($url, $file);

  write-host " saved." -ForeGroundColor yellow
}

$wc.Dispose()

vedi anche PowerShell: download di una pagina web
Tags:
PowerShell199 Script85
Potrebbe interessarti anche: