SynchronizeDirectories returns empty collection in SynchronizationResult.Removals

Advertisement

MarisB
Joined:
Posts:
19

SynchronizeDirectories returns empty collection in SynchronizationResult.Removals

First, thanks for your software! :)

I am using SynchronizeDirectories to sync local files to Ubuntu server, and vica versa using SFTP Protocol. When syncing to SFTP server, the SynchronizationResult.Removals have list of removed files. When syncing from SFTP server to local, the Removals are empty list.

I have reduced this to very simple test case. One side has an empty folder, other - one file. I have enabled logging, and also capturing .xml file by placing break-point at XML file deleting in Session.cs file:
Logger.WriteLine("Deleting XML log file [{0}]", XmlLogPath);
try
{
    File.Delete(XmlLogPath);
}

When syncing from local to SFTP, the XML file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="MY_SERVER_NAME" start="2019-07-18T13:36:17.488Z">
  <group name="sftp://ubuntu@MY_SERVER_NAME:22 -hostkey=&quot;ssh-rsa 2048 *************************=&quot; -privatekey=&quot;C:\key.ppk&quot; -timeout=60 -passphrase=***" start="2019-07-18T13:36:20.219Z">
  </group>
  <group name="" start="2019-07-18T13:36:21.029Z">
    <cwd>
      <cwd value="/home/ubuntu" />
      <result success="true" />
    </cwd>
  </group>
  <group name="remote -delete  -nopermissions -preservetime -transfer=&quot;binary&quot; -resumesupport=&quot;off&quot; -criteria=&quot;either&quot;  -- &quot;c:\test case\&quot; &quot;/home/ubuntu/the test directory/&quot;" start="2019-07-18T13:36:21.108Z">
    <rm>
      <filename value="/home/ubuntu/the test directory/first file.txt" />
      <result success="true" />
    </rm>
  </group>
  <group name="" start="2019-07-18T13:36:21.942Z">
  </group>
</session>
There is entry rm in the XML file, and SynchronizationResult.Removals have one entry. So far so good. Now I try sync in other direction. Capturing XML file:
<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="ubuntu@MY_SERVER_NAME" start="2019-07-18T13:06:40.914Z">
  <group name="sftp://ubuntu@MY_SERVER_NAME:22 -hostkey=&quot;ssh-rsa 2048 *************************=&quot; -privatekey=&quot;C:\some_key.ppk&quot; -timeout=60 -passphrase=***" start="2019-07-18T13:06:43.509Z">
  </group>
  <group name="" start="2019-07-18T13:06:43.611Z">
    <cwd>
      <cwd value="/home/ubuntu" />
      <result success="true" />
    </cwd>
  </group>
  <group name="local -delete  -nopermissions -preservetime -transfer=&quot;binary&quot; -resumesupport=&quot;off&quot; -criteria=&quot;either&quot;  -- &quot;c:\test case\&quot; &quot;/home/ubuntu/the test directory/&quot;" start="2019-07-18T13:06:43.692Z">
  </group>
  <group name="" start="2019-07-18T13:06:44.555Z">
  </group>
</session>
There is no entry for rm, and Removals are also empty. However, the file is synced correctly (deleted), and other log file also have clue that file was deleted:
> 2019-07-18 16:06:44.067 Type: SSH_FXP_CLOSE, Size: 13, Number: 1028
> 2019-07-18 16:06:44.067 04,00,00,04,04,00,00,00,04,00,00,00,00,
. 2019-07-18 16:06:44.067 Sent 17 bytes
. 2019-07-18 16:06:44.067 There are 0 bytes remaining in the send buffer
. 2019-07-18 16:06:44.067 Looking for network events
. 2019-07-18 16:06:44.067 Timeout waiting for network events
. 2019-07-18 16:06:44.067 .;d;0;2019-07-18T13:02:37.000Z;3;"ubuntu" [1000];"ubuntu" [1000];rwxrwxr-x;0
. 2019-07-18 16:06:44.067 ..;d;0;2019-07-18T13:02:37.000Z;3;"ubuntu" [1000];"ubuntu" [1000];rwxr-xr-x;0
. 2019-07-18 16:06:44.067 Local file 'c:\test case\first file.txt' [2019-07-18T13:06:33.882Z] [1] is new
< 2019-07-18 16:06:44.067 Script: Synchronizing...
. 2019-07-18 16:06:44.067 Synchronizing local directory 'c:\test case\' with remote directory '/home/ubuntu/the test directory/', params = 0x403 (Delete, NoConfirmation, BySize)
< 2019-07-18 16:06:44.068 Script: Local 'c:\test case' <= Remote '/home/ubuntu/the test directory'
< 2019-07-18 16:06:44.140 Script: 'c:\test case\first file.txt' deleted
. 2019-07-18 16:06:44.187 Session upkeep
. 2019-07-18 16:06:44.187 Looking for network events
. 2019-07-18 16:06:44.187 Detected network event
. 2019-07-18 16:06:44.187 Enumerating network events for socket 1324
. 2019-07-18 16:06:44.187 Enumerated 1 network events making 1 cumulative events for socket 1324
. 2019-07-18 16:06:44.187 Handling network read event on socket 1324 with error 0
. 2019-07-18 16:06:44.187 Received 28 bytes (0)
> 2019-07-18 16:06:44.555 Script: exit
. 2019-07-18 16:06:44.555 Session upkeep
Am I doing something wrong? If you need more information, I will gladly provide it.

Thanks in advance! :)

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,669
Location:
Prague, Czechia

Re: SynchronizeDirectories returns empty collection in SynchronizationResult.Removals

As the documented, the SynchronizationResult.Removals is "Collection of remote file removals".
https://winscp.net/eng/docs/library_synchronizationresult#removals
Local file removals are not returned currently.

See this example how to use CompareDirectories to find list of files needing synchronization (including removal) and applying those changes (it's in PowerShell though):
Keep local directory up to date (download changed files from remote SFTP/FTP server)
Last edited by martin on 2024-05-02; edited 3 times in total

Reply with quote

morten.strand@km.kongsberg.com
Joined:
Posts:
1
Location:
Kongsberg

Re: SynchronizeDirectories returns empty collection in SynchronizationResult.Removals

Hello,
I would highly want the SynchronizationResult to include information of the the local file removals. Without this, I need to run CompareDirectories to find out what local files that will be removed, and that method call makes the code run twice as slow since those to methods take almost the same time to execute.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,669
Location:
Prague, Czechia

Re: SynchronizeDirectories returns empty collection in SynchronizationResult.Removals

I have added this request to the tracker:
Issue 2287 – Record local file removals when synchronizing in .NET assembly and scripting
You can vote for it there.

Though note that if you use CompareDirectories, you do not need to call SynchronizeDirectories. You call apply the differences identified by the CompareDirectories. See Keep local directory up to date (download changed files from remote SFTP/FTP server)

Reply with quote

Advertisement

You can post new topics in this forum