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
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