In Rebex SFTP, the same functionality can be achieved by calling the Sftp.Session.KeepAlive method every minute or so. This sends null data to the server to keep the connection alive. Although this is not done automatically by Rebex SFTP (yet), it can be safely called from any thread, which makes reproducing the "ServerAliveInterval" functionality quite easy:
///
/// Enhanced Sftp class which implements the keep-alive functionality.
/// Use this instead of Sftp in your code.
///
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 = new TimeSpan(0, 1, 0);
_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 you prefer VB.NET, please let us know!