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.

Advertisements:

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 *>=2013-09-19.

For scripting, you need to generate the mask using your favorite scripting language.1)

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

$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = ("*>=" + $(Get-Date -f "yyyy-MM-dd"))
 
$session.PutFiles("d:\toupload\*", "/home/user/", $False, $transferOptions)

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

1) See Downloading file to timestamped-filename article for timestamp generation.
 
  faq_script_modified_files.txt · Last modified: by martin
 

Search Documentation

This page

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

Associations

Site design by Black Gate