How do I transfer new/modified files only?

When destination directory contains old files

When your destination directory already contains all the previously transferred files, synchronize source directory to destination directory, instead of simple transfer.


Basically use synchronize local instead of get and synchronize remote instead of put.

With WinSCP .NET assembly that means, use Session.SynchronizeDirectories, with argument mode set to SynchronizationMode.Remote or SynchronizationMode.Local instead of Session.GetFiles or Session.PutFiles respectively.

When destination directory does not contain old files

When the old files are removed from the destination directory, you can instead select the new files based on timestamp.

For that you can use file mask with time constraint. For example, to transfer only files created/modified since yesterday, use mask *>=1D (means all files modified in the last 24 hours).

In scripting, apply the mask using -filemask=<mask> switch of get or put commands.

For example:

put -filemask="*>=1D" *

In WinSCP .NET assembly, use TransferOptions.FileMask. PowerShell example:

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "*>=1D"
$session.PutFiles("d:\toupload\*", "/home/user/", $False, $transferOptions)

If you need to select file specifically created/modified today (not simply in the last 24 hours), you need to generate a file mask with absolute timestamp constraint, like *>=2017-05-12.

In scripting, can also use %TIMESTAMP% syntax to generate “today” time constraint, e.g. *>=%TIMESTAMP#yyyy-mm-dd%.

In WinSCP .NET assembly, use System.DateTime class. For example in PowerShell:

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = ("*>=" + $(Get-Date -Format "yyyy-MM-dd"))
$session.PutFiles("d:\toupload\*", "/home/user/", $False, $transferOptions)
  faq_script_modified_files.txt · Last modified: by martin

Search Documentation

This page


About donations

$9   $19   $49   $99

About donations



Site design by Black Gate