Download files and move after download on to the remote server
Hi
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
I used this example:
Moving local files to different location after successful upload
This is my code:
Thanks
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
I used this example:
Moving local files to different location after successful upload
This is my code:
$localpath = "C:\Temp\Download\" $remotepath = '//*' $remotepathbackup = '/backup/' $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # 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 $session.MoveFile(($transfer.FileName), $remotepathbackup) } else { Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)" } } } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch { Write-Host "Error: $($_.Exception.Message)" exit 1 }