I\'d like to automate the FTP download of a database backup file using PowerShell. The file name includes the date so I can\'t just run the same FTP script every day. Is t
The most voted self-answer by @Eric is working, but it is:
$fileUrl = "ftp://ftp.example.com/remote/path/file.zip"
$localFilePath = "C:\local\path\file.zip"
$downloadRequest = [Net.WebRequest]::Create($fileUrl)
$downloadRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$downloadRequest.Credentials =
New-Object System.Net.NetworkCredential("username", "password")
# Enable secure FTPS (FTP over TLS/SSL)
$downloadRequest.EnableSsl = $True
$sourceStream = $downloadRequest.GetResponse().GetResponseStream()
$targetStream = [System.IO.File]::Create($localFilePath)
$sourceStream.CopyTo($targetStream);
$sourceStream.Dispose()
$targetStream.Dispose()
For an upload, see Upload files with FTP using PowerShell.