Hello! I'm getting the following exception when executing directory sync with permissions set:
Exception calling "SynchronizeDirectories" with "7" argument(s): "Tag chmod before tag download"
The most strange thing here is that script does its job and files are transferred correctly as far as I can judge. Even permissions are correct.
Here's my script's main part code:
try {
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = $PuppetSrvIP
UserName = $PuppetSrvUserName
GiveUpSecurityAndAcceptAnySshHostKey = $True
SshPrivateKeyPath = $PuppetSrvKeyFile
#SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}
$session = New-Object WinSCP.Session
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "$($Include -join ";")|$($Exclude -join ";")"
$transferOptions.FilePermissions = New-Object WinSCP.FilePermissions
$transferOptions.FilePermissions.Octal = "$Permissions"
try {
# Will continuously report progress of synchronization
$session.add_FileTransferred( { FileTransferred($_) } )
# Connect
$session.Open($sessionOptions)
if ($NoCleanup) {
$Cleanup = $False
}
else {
$Cleanup = $True
}
# Synchronize files
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Remote, $SourcePath, $TargetPath, $Cleanup, $False, [WinSCP.SynchronizationCriteria]::Time, $transferOptions)
# Throw on any error
$synchronizationResult.Check()
}
finally {
# Disconnect, clean up
$session.Dispose()
}
Write-Host "Successfully synced directories"
if ($NoCleanup) {
Write-Host "No cleanup was performed"
}
}
catch {
$Exception = $_.Exception
Write-Error "Error: $($Exception.Message)"
}
How can I debug this strange behavior? I've checked session logs but nothing suspicious was found except the same exception.
Also, I've noticed that
FileTransferred
event handler stopped working after I added
FilePermissions
option. I'm using event handler from
this example.