Apparently, the KeepAlive()
method does not change the State
property. This is a bug and we will fix this in a future version has been fixed in Rebex SFTP 2019 R3.
I have updated the SftpKeepAlive
sample class to workaround this issue.
public class SftpKeepAlive : Sftp
{
// Timer object (needs to be referenced to prevent it from being
// claimed by the garbage collector).
private readonly System.Threading.Timer _keepAliveTimer;
public SftpKeepAlive()
{
// initialize the timer
var oneMinute = TimeSpan.FromSeconds(60);
_keepAliveTimer = new System.Threading.Timer(KeepAliveCallback, null, oneMinute, oneMinute);
}
private void KeepAliveCallback(object state)
{
try
{
if (State == SftpState.Ready)
{
// send keep-alive packet to the server
Session.KeepAlive();
}
}
catch (Exception ex)
{
// log the exception here
// ...
if (State == SftpState.Ready)
{
// KeepAlive() do not change State currently, raise event manually
OnStateChanged(new SftpStateChangedEventArgs(State, SftpState.Disconnected));
}
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
// dispose the timer
_keepAliveTimer.Dispose();
}
}
}