Timeout set to 0 ?
I've lost you there : the code looks as follows :
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WINSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "XXXXXXX"
$sessionOptions.UserName = "XXXXXXX"
$sessionOptions.Password = "XXXXXXX"
$sessionOptions.Timeout = 300
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa XXXXXX"
$session = New-Object WinSCP.Session
try
{
# Connect
$session.ExecutablePath = "C:\Program Files (x86)\WINSCP\winscp.exe"
$Session.SessionLogPath = "C:\Scripts\copy.log"
# $Session.DebugLogPath = "C:\Scripts\copydebug.log"
$session.Open($sessionOptions)
# Synchronize files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.SpeedLimit = 6000
$transferResult_Data = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Local, "E:\PRD_BACKUPS\DATA\", "/hana/hana-backup/PRD/data/",$true,$false,[WinSCP.SynchronizationCriteria]::Time,$transferOptions)
$transferResult_Data.Check()
$transferResult_Logs = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Local, "E:\PRD_BACKUPS\LOGS\", "/hana/hana-backup/PRD/log/",$true,$false,[WinSCP.SynchronizationCriteria]::Time,$transferOptions)
$transferResult_Logs.Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
Send-MailMessage -From "hostname" -To "XXXXXXXXX" -Subject "synchronization of backupfiles (DATA & LOGS) from <hostname> to <hostname> finished OK" -SmtpServer "yyy"
exit 0
}
catch [Exception]
{
$ErrorMessage = $_.Exception.Message
Send-MailMessage -From "hostname" -To "XXXXXXXXX" -Subject "synchronization of backupfiles (DATA or LOGS) from <hostname> to <hostname> FAILED !" -SmtpServer "yyy" -Body "Error message is $ErrorMessage"
exit 1
}