SynchronizeDirectories does not preserve all timestamps

Advertisement

p0d
Joined:
Posts:
2
Location:
United Kingdom

SynchronizeDirectories does not preserve all timestamps

Hi,

I transfer many directories using Winscp between two Windows 2012 R2 servers and find a number of remote files do not preserve the timestamp of the local file.

If I understand the docs correctly the code I'm using below should sync timestamps by default. Is there a workaround to make sure all timestamps are synced?

try
{
[Reflection.Assembly]::LoadFrom("inSCPnet.dll") | Out-Null
$session = New-Object WinSCP.Session
$session.ExecutablePath = "C:\Scripts\HostedDeploy\functions\winscp552automation\WinSCP.exe"

# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp

$sessionOptions.HostName = $this_server.Get_Item("remote_ip")
$sessionOptions.PortNumber = "22"
$sessionOptions.SshPrivateKeyPath = $this_server.Get_Item("remote_key")
$sessionOptions.UserName = "Administrator"
$sessionOptions.SshHostKeyFingerprint = $this_server.Get_Item("remote_fingerprint")

$session = New-Object WinSCP.Session
try
{
$session.Open($sessionOptions)
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, $local, $remote, $True)
$synchronizationResult.Check()
}
finally
{
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}

Many thanks,

Chris

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: SynchronizeDirectories does not preserve all timestamps

p0d wrote:

I transfer many directories using Winscp between two Windows 2012 R2 servers and find a number of remote files do not preserve the timestamp of the local file.
Can you be more specific about what "remote files do not preserve the timestamp of the local file"?

If I understand the docs correctly the code I'm using below should sync timestamps by default. Is there a workaround to make sure all timestamps are synced?
No, it does not "sync timestamps". It synchronizes files. If you assumed that timestamps of existing files will be synchronized, then it won't. "Synchronize timestamps" mode in not available in .NET assembly. Though you can use "mirror mode" (5th argument of Session.SynchronizeDirectories) to synchronize files even if their timestamps are "older", what will effectively (while not efficiently) synchronize even the timestamps.
https://winscp.net/eng/docs/library_session_synchronizedirectories#mirror

Reply with quote

p0d
Joined:
Posts:
2
Location:
United Kingdom

Thanks Martin, I didn't realise sync of timestamps was an issue with .net.

I may have one or two files in a group of fifty sync with very different created/modify times than the original file. One remote file I am looking at right now is 7 hours out regards the local file's create/modify. My guess is the problem remote file times are when the file finished uploading, not the original create/modify time.

It's a nuisance for me as I restore a full sql backup then hourly logs based on these file's timestamps. I think I'll go for a Plan B as I'm looking at a dozen failed restored backups every Monday morning.

Thanks again.

Chris

Reply with quote

Advertisement

You can post new topics in this forum