Topic ""Remote Sync" Get list of files removed from FTP site"

Author Message
kenny782
[View user's profile]

Joined: 2017-06-29
Posts: 3
Location: New York
So I have done alot of searching without luck.

I'm doing a one way sync Local to Remote(FTP) via Powershell
It's working great and I worked in some reporting and email.

Problem
One thing I can't figure out how to do....
I want to capture a list of any files that are removed on the FTP site (because they no longer exist locally).

However I can't find an event or example to do that.
I found an example using Get-ChildItem -Recurse But that was designed to capture the local directory before and after.
I need to either list the FTP site before and after to compare or discover an event I haven't found that will let me append to my log file what was removed.

Seems like a worthy Feature Request for SynchronizeDirectories Very Happy


And this isn't a must but if anyone has any ideas on how I can tell the difference between a new file uploaded vs an existing file I just updated from local that would be nice

Code:

function FileTransferred
{
   param ($e)
   
   if ($e.Error -eq $Null)
   {
      Write-Host ("Upload of {0} succeeded" -f $e.FileName)
      Add-Content -Path $LogFile -Value ( "`nUpload of file succeeded"+"   "+$e.FileName )
   }
   else
   {
      Write-Host ("Upload of {0} failed: {1}" -f $e.FileName, $e.Error)
      Add-Content -Path $LogFile -Value ( "`nUpload of file failed: "+"   "+$e.FileName+"    Error: "+$e.Error )
   }
   
<#   if ($e.Chmod -ne $Null)
   {
      if ($e.Chmod.Error -eq $Null)
      {
         Write-Host ("Permisions of {0} set to {1}" -f $e.Chmod.FileName, $e.Chmod.FilePermissions)
      }
      else
      {
         Write-Host ("Setting permissions of {0} failed: {1}" -f $e.Chmod.FileName, $e.Chmod.Error)
      }
      
   }
   else
   {
      Write-Host ("Permissions of {0} kept with their defaults" -f $e.Destination)
   }
   
   if ($e.Touch -ne $Null)
   {
      if ($e.Touch.Error -eq $Null)
      {
         Write-Host ("Timestamp of {0} set to {1}" -f $e.Touch.FileName, $e.Touch.LastWriteTime)
      }
      else
      {
         Write-Host ("Setting timestamp of {0} failed: {1}" -f $e.Touch.FileName, $e.Touch.Error)
      }
      
   }
   else
   {
      # This should never happen during "local to remote" synchronization
      Write-Host ("Timestamp of {0} kept with its default (current time)" -f $e.Destination)
   }#>
}



Thanks,

Kenny Smile
FTP Upload Script.ps1.txt (5.3 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26462
Location: Prague, Czechia
There's no event for that.

But you can get list of all removals (as well as all uploads=updates) from SynchronizationResult returned by Session.SynchronizeDirectories:
https://winscp.net/eng/docs/library_synchronizationresult
Advertisements

You can post new topics in this forum






Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License