Options

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

mixolydian

## Re: PowerShell Synchronize mode 'Both' with Transfer Options

I figured it out. I did not address the required passing of the parameters in the $session.SynchronizeDirectories() statement between the 4th parameter that I set as false and the transfer options, which would be the transferoptions, which would be the 7th parameter. I did not really understand what you meant with your response to the OP with you example. After time to review I based it on your example and wallah!!! Fix: # Synchronize files$synchronizationResult = $session.SynchronizeDirectories( [WinSCP.SynchronizationMode]::Both, "E:\data\em", "/usr/local/em",$false, $false, [WinSCP.SynchronizationCriteria]::Time,$transferoptions)

I considered deleting the post but figured someone else may have the same confusion.
I really loved the .NET Assembly / COM Library!
https://winscp.net/eng/docs/library

I will be donating soon so you will continue your journey on supporting this awesome project!
mixolydian

## Re: PowerShell Synchronize mode 'Both' with Transfer Options

I have possible similar syntax problems related to FileMask, or the method is not implemented for [WinSCP.SynchronizationMode]::Both.

Code snippet:
# Connect$session.Open($sessionOptions) #Transfer options$transferoptions = New-Object WinSCP.TransferOptions -Property @{ FileMask = "| temporary.wav"} # Synchronize files$synchronizationResult = $session.SynchronizeDirectories( [WinSCP.SynchronizationMode]::Both, "E:\data\em", "/usr/local/em",$false, $transferoptions) But I get the error: Error: Exception calling "SynchronizeDirectories" with "5" argument(s): "Cannot mirror files in synchronization mode Both" Transfers work without the $transferoptions in the $session.SynchronizeDirectories() but I need to exclude the transfer of specific files/types from ever being transmitted. I also tried using the syntax from the OP for the transfer options with the same resulting error. johnhamborg ## PowerShell Synchronize mode 'Both' with Transfer Options I am struggling to include $TransferOptions when using Synchronize mode 'Both'. I looked through loads of documentation but just couldn't figure out how to make it work in powershell. Thanks for the support!

Here is a snippet of modified code based on the included 'KeepLocalUpToDate' extension.

Write-Host "Connecting..."$session.Open($sessionOptions) #Setup Transfer Options$transferOptions = New-Object WinSCP.TransferOptions$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off$TransferOptions.FilePermissions = New-Object WinSCP.FilePermissions$TransferOptions.FilePermissions.Octal = 0777 while ($True){ Write-Host "Synchronizing changes..."$result =        $session.SynchronizeDirectories( [WinSCP.SynchronizationMode]::Both,$localPath, $remotePath,[WinSCP.SynchronizationCriteria]::$TransferOptions )