Remote synchronize, delete removed files but not folders

Advertisement

mhystique
Joined:
Posts:
2

Remote synchronize, delete removed files but not folders

Hi
I'm trying to set up a PowerShell script, which should synchronize multiple folders to an FTP server. My problem is, that one specific local folder should be synchronized to a remote subfolder, and therefore the subfolder gets deleted.
How do I do that, without losing the ability to delete files, which has been deleted in a local folder?
Lets say I need to do the following:
Local path | Remote path
\\server\folder1\subfolder1\ | /FTP server/folder1/subfolder1/
\\server\folder1\subfolder2\ | /FTP server/folder1/subfolder1/subsubfolder1/

There are several other subfolders in folder1, but I only need to sync subfolder1 and subfolder2. And if a file is deleted from the local path, is should also be deleted on the FTP.

My sync is like this:
# Synchronize files
for ($i=0; $i -lt $localePathArray.length; $i++) {
       $synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, $localePathArray[$i], $remotePathArray[$i], $True) 
}

Reply with quote

Advertisement

mhystique
Joined:
Posts:
2

I may have figured it out myself. Found a webpage telling about masks together with directories. So I tried this, and it seems to work.

$TransferOptions = New-Object WinSCP.TransferOptions 
$TransferOptions.FileMask = "|*/"
    # Synchronize files
    for ($i=0; $i -lt $localePathArray.length; $i++) {
       # Write-Host "$localePathArray[$i] $remotePathArray[$i]"
    
        $synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, $localePathArray[$i], $remotePathArray[$i], $True, $False, [WinSCP.SynchronizationCriteria]::Time, $TransferOptions)
    }

Reply with quote

Advertisement

You can post new topics in this forum