I want to download data and then move it on the remote server. I want to keep the folder structure. And exclude the backupfolder for downloading
$localpath = "C:\Temp\Download\"
$remotepath = '//*'
$remotepathbackup = '/backup/'
$session = New-Object WinSCP.Session
# Download files, collect results
$transferResult = $session.GetFiles($remotepath, $localpath)
# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
# Success or error?
if ($transfer.Error -eq $Null)
Write-Host "Download of $($transfer.FileName) succeeded, moving to backup"
# Upload succeeded, move source file to backup
Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)"
# Disconnect, clean up
Write-Host "Error: $($_.Exception.Message)"