Session.SynchronizeDirectories Method Powershell not removing remote files

Advertisement

rfiscus
Joined:
Posts:
4

Session.SynchronizeDirectories Method Powershell not removing remote files

I am using the PowerShell version of Session.SynchronizeDirectories Method located at https://winscp.net/eng/docs/library_session_synchronizedirectories#powershell
It all works really well for new files that need to be uploaded to the remote server. It does not seem to remove remote files if they are no longer on the local server. How can I make it also remove the remote files if they no longer exist locally?

Reply with quote

Advertisement

rfiscus
Joined:
Posts:
4

Re: Session.SynchronizeDirectories Method Powershell not removing remote files

martin wrote:

Did you set the removeFiles argument to true?

How, I don't see that option in PowerShell, only the other languages?

Reply with quote

martin
Site Admin
martin avatar

Re: Session.SynchronizeDirectories Method Powershell not removing remote files

I do not understand. The method is just one. There are no variants for different languages.

Reply with quote

rfiscus
Joined:
Posts:
4

Session.SynchronizeDirectories Method Powershell not removing remote files

The functions listed are for C# and VB.net, I don't see the syntax of the function to add it to the PowerShell script. If you are saying I can use the C# or VB.net function from within the PowerShell version, where would I place the function[/code]?
C#
public SynchronizationResult SynchronizeDirectories(
    SynchronizationMode mode,
    string localPath,
    string remotePath,
    bool removeFiles,
    bool mirror = false,
    SynchronizationCriteria criteria = SynchronizationCriteria.Time,
    TransferOptions options = null
)

Where in PowerShell would I add removeFiles?

Reply with quote

Advertisement

sd-guest
Guest

Please check $session.SynchronizeDirectories in the script. First parameter is the sync mode, second is local path, third is remote path, and then removeFiles, which is $False in the example script. When I got that right, the latter should be changed to $True.

Reply with quote

rfiscus
Joined:
Posts:
4

sd-guest wrote:

Please check $session.SynchronizeDirectories in the script. First parameter is the sync mode, second is local path, third is remote path, and then removeFiles, which is $False in the example script. When I got that right, the latter should be changed to $True.

That tries to delete the remote files instead of the local files that were just copied to the remote server.

Reply with quote

sd-guest
Guest

I was referring to the post of martin and his suggestion. I have not checked the script itself.

That tries to delete the remote files instead of the local files that were just copied to the remote server.

Isn't it that what you wanted?

It does not seem to remove remote files if they are no longer on the local server. How can I make it also remove the remote files if they no longer exist locally?

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: Session.SynchronizeDirectories Method Powershell not removing remote files

rfiscus wrote:

Where in PowerShell would I add removeFiles?
The PowerShell example you have referred to yourself passes a $False value to the removeFiles argument:
https://winscp.net/eng/docs/library_session_synchronizedirectories#powershell
$synchronizationResult = $session.SynchronizeDirectories(
    [WinSCP.SynchronizationMode]::Remote, "d:\www",
    "/home/martin/public_html", $False)
I assume you just want to replace it with $True.

Reply with quote

Advertisement

You can post new topics in this forum