Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: Sync only level 1 directory issue

Do I understand right, that it's taking too long, because finding the new files itself takes too long already. Right?

WinSCP does not support time constraints for directories. So this is not doable using a file mask only.

But you can identify folder candidates programmatically and run separate synchronizations just for those.

# List files
$directoryInfo = $session.ListDirectory("/remote/path")
# Find recent folders
$limit = (Get-Date).AddDays(-15)
$recentFolders =
    $directoryInfo.Files |
    Where-Object { $_.IsDirectory } |
    Where-Object { $_.LastWriteTime -gt $limit }
# Synchronize them
foreach ($recentFolder in $recentFolders)
    $localPath = "C:\local\path\" + $recentFolder.Name
    New-Item -ItemType Directory -Force -Path $localPath | Out-Null
        [WinSCP.SynchronizationMode]::Local, $recentFolder.FullName,
        $localPath, $False).Check()


Sync only level 1 directory issue


I am currently running a sync script to copy everything from a remote folder to my local folder. This is working fine, but I'm currently running into the issue of the sync job taking a long time. The remote folder is growing weekly, so the process is taking longer every time new files are created.

I haven't been able to successfully use the timestamp option to only sync new files because the remote folder has new folders created, but the underlying files in the folder are often timestamped older, which causes these files not to be copied over. The folder itself has a new timestamp, but the underlying files do not.

So my question: is there a way to check just the directories under a specified directory, and if the subdirectory itself is newer, then copy the entire subdirectory from the remote to the local?

I attached the current sync script.