Skip to content

Instantly share code, notes, and snippets.

@atao
Last active April 25, 2019 15:21
Show Gist options
  • Save atao/89fa3b79cdf3ed574f0c1c3adc4e3394 to your computer and use it in GitHub Desktop.
Save atao/89fa3b79cdf3ed574f0c1c3adc4e3394 to your computer and use it in GitHub Desktop.
function SendByFTP
function SendByFTP {
param (
$userFTP = "anonymous",
$passFTP = "anonymous",
[Parameter(Mandatory=$True)]$serverFTP,
[Parameter(Mandatory=$True)]$localFile,
[Parameter(Mandatory=$True)]$remotePath
)
if(Test-Path $localFile){
$remoteFile = $localFile.Split("\")[-1]
$remotePath = Join-Path -Path $remotePath -ChildPath $remoteFile
$ftpAddr = "ftp://${userFTP}:${passFTP}@${serverFTP}/$remotePath"
$browser = New-Object System.Net.WebClient
$url = New-Object System.Uri($ftpAddr)
$browser.UploadFile($url, $localFile)
}
else{
Return "Unable to find $localFile"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment