Thanks for your donation. And good luck to Ukraine!
- martin
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, $localPath, $remotePath, $False, $False, [WinSCP.SynchronizationCriteria]::None, New-Object New-Object WinSCP.TransferOptions -Property @{ ResumeSupport = New-Object WinSCP.TransferResumeSupport -Property @{ State = [WinSCP.TransferResumeSupportState]::On } } )
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::On
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, $localPath, $remotePath, $False, $False, [WinSCP.SynchronizationCriteria]::None, $transferOptions)
Session.SynchronizeDirectories
with SynchronizationCriteria.None
should do what you want.
In this case, if the file is not fully loaded due to error it is placed as *._filename which is ok.
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = $HostName
UserName = $UserName
Password = $Password
SshHostKeyFingerprint = $SshHostKeyFingerprint
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Timeout = New-TimeSpan -Seconds 120
$session.Open($sessionOptions)
# Syncronize
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Remote, $localPath, $remotePath, $False)
$files = $session.EnumerateRemoteFiles($remotePath, $wildcard, [WinSCP.EnumerationOptions]::AllDirectories)
# Find old files
$limit = (Get-Date).AddDays($oldDate)
$oldFiles =
$files |
Where-Object { -Not $_.IsDirectory } |
Where-Object { $_.LastWriteTime -lt $limit }
# Delete them
foreach ($oldFileInfo in $oldFiles)
{
$session.RemoveFiles($oldFileInfo.FullName).Check()
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0