With WinSCP 5.16.5
ComparisonDifference.Resolve
, the code can be simplified to:
$diffs = $session.CompareDirectories(
[WinSCP.SynchronizationMode]::Remote, $localPath, $remotePath, $True)
foreach ($diff in $diffs)
{
if ($diff.Action -eq [WinSCP.SynchronizationAction]::DeleteRemote)
{
Write-Host "Deleting $($diff.Remote.FileName)..."
$diff.Resolve($session) | Out-Null
}
}
foreach ($diff in $diffs)
{
if (($diff.Action -eq [WinSCP.SynchronizationAction]::UploadNew) -or
($diff.Action -eq [WinSCP.SynchronizationAction]::UploadUpdate))
{
Write-Host "Uploading $($diff.Local.FileName)..."
$diff.Resolve($session) | Out-Null
}
}