Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

johnhamborg

Solved

Thanks for the pointer.

I ended up implementing it like this
$synchronizationResult =
    $session.SynchronizeDirectories(
        [WinSCP.SynchronizationMode]::Remote, $localPath, $remotePath,
        $True, $False, [WinSCP.SynchronizationCriteria]::Time,
        $transferOptionsSync)
 
# Removals
$Removals = $synchronizationResult.Removals
ForEach ($file in $Removals) {
    Write-Host "Deleted " $File.FileName
}
johnhamborg

Write Host on Removal of Files during Synchronize with RemoveFiles enabled – PowerShell

I am largely following the template provided here
https://winscp.net/eng/docs/library_session_synchronizedirectories#example

I have configured the Removal of Files during Synchronize with removeFiles enabled and I need to write out the status of those operations along with the other sync operations.

In the example, all errors and status are sent through the FilesTransferred function, how do I include the removed files as well?

I tried to add this $e.Removal case, but it does not seem to work.

if ($e.Touch -ne $Null)
{
    if ($e.Touch.Error -eq $Null)
    {
        Write-Host "Timestamp of $($e.Touch.FileName) set to $($e.Touch.LastWriteTime)"
    }
    else
    {
        Write-Host "Setting timestamp of $($e.Touch.FileName) failed: $($e.Touch.Error)"
    }
}
 
 
if ($e.Removal -ne $Null)
{
    if ($e.Removal.Error -eq $Null)
    {
        Write-Host "Deleted $($e.Removal.FileName) "
    }
    else
    {
        Write-Host "Could not Delete $($e.Removal.FileName): $($e.Removal.Error)"
    }
 
}
else
{
    # This should never happen during "local to remote" synchronization
    Write-Host "Timestamp of $($e.Destination) kept with its default (current time)"
}

Thanks