Last active
February 27, 2020 11:19
-
-
Save atao/9542f4bc3a10c2a9d7b94a3da7edad5f to your computer and use it in GitHub Desktop.
function GetByFTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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