Skip to content

Instantly share code, notes, and snippets.

@atao
Last active February 27, 2020 11:19
Show Gist options
  • Save atao/9542f4bc3a10c2a9d7b94a3da7edad5f to your computer and use it in GitHub Desktop.
Save atao/9542f4bc3a10c2a9d7b94a3da7edad5f to your computer and use it in GitHub Desktop.
function GetByFTP
function GetByFTP()
{
param (
$userFTP = "anonymous",
$passFTP = "anonymous",
[Parameter(Mandatory=$True)]$serverFTP,
[Parameter(Mandatory=$True)]$localPath,
[Parameter(Mandatory=$True)]$remoteFile
)
$localFile = Join-Path -Path $localPath -ChildPath $remoteFile.split('/')[-1]
if(!(Test-Path $localFile)){
$password = convertto-securestring -String $passFTP -AsPlainText -Force
$Creds = new-object -typename System.Management.Automation.PSCredential -argumentlist $userFTP, $password
Invoke-WebRequest -Uri "ftp://$serverFTP/$remoteFile" -OutFile $localFile -Credential $Creds
if(Test-Path $localFile){
Write-Host "[SUCCESS]`t$localFile downloaded!"
} else {
Write-Host "[ERROR]`tUnable to download : $localFile"
}
} else {
Write-Host "[SKIP]`t$localFile already exist!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment