Powershell SynchronizeDirectories Failing with a Permission Error on a Single File

Advertisement

andshrew
Joined:
Posts:
1

Powershell SynchronizeDirectories Failing with a Permission Error on a Single File

I'm using the Session.SynchronizeDirectories method to try and syncronise files from a remote location to a local one. This is working fine except when it encounters a file which it cannot copy (eg. permission error). When this happens the process instantly stops the sync.

The output from SyncronizationResult is:
Failures  : {WinSCP.SessionRemoteException: Cannot open remote file '/file.log'.
Permission denied.
Error code: 3
Error message from server: Permission denied}

I set it to output the full log file, an extract from this:
. 2018-09-28 16:43:37.892 Asking user:
. 2018-09-28 16:43:37.892 Cannot open remote file '/file.log'. ("Permission denied.
. 2018-09-28 16:43:37.892 Error code: 3
. 2018-09-28 16:43:37.892 Error message from server: Permission denied")
< 2018-09-28 16:43:37.892 Script: Cannot open remote file '/file.log'.
< 2018-09-28 16:43:37.892 Script: Permission denied.
< 2018-09-28 16:43:37.892 Error code: 3
< 2018-09-28 16:43:37.892 Error message from server: Permission denied
* 2018-09-28 16:43:37.892 (EScpSkipFile) Cannot open remote file '/file.log'.
* 2018-09-28 16:43:37.892 Permission denied.
* 2018-09-28 16:43:37.892 Error code: 3
* 2018-09-28 16:43:37.892 Error message from server: Permission denied
. 2018-09-28 16:43:37.892 Copying finished: Transferred: 0, Elapsed: 0:00:00, CPS: 0/s
. 2018-09-28 16:43:37.892 Script: Failed
> 2018-09-28 16:43:43.958 Script: exit
. 2018-09-28 16:43:43.968 Script: Exit code: 1

From searching and the 'Asking User' entry in the log it seems like I need to handle what it does when it encounters an error like this. I found this example of how to implement an event handler for QueryReceived in Powershell but either the example of wrong or not compatible with my version as I just get an error saying:
Method invocation failed because [WinSCP.Session] does not contain a method named 'add_QueryReceived'.

What I want to happen is for it to just continue syncronising if it encounters an error like this. Can anyone advise how I can configure it to do this?

I'm using Powershell 4.0 with WinSCP version 5.11.2

Thanks

Andrew

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
29,303
Location:
Prague, Czechia

Re: Powershell SynchronizeDirectories Failing with a Permission Error on a Single File

Session.QueryReceived has been added in 5.12.1. Download the latest version of WinSCP.
https://winscp.net/tracker/1594

Reply with quote

Advertisement

You can post new topics in this forum