Actually, when the connection is closed gracefully, the
CheckConnectionState should be able to detect it. However, if a connection is lost without the client machine being aware of it (and this actually happens on unstable connections), the only way to detect the failure is to send a packet to the server first. This means that the event would have to do that as well, which would kind-of defeat its purpose - the lost connection check would have to be performed periodically every few seconds and would not be able to detect the failure instantly.
Why not just wrap the FTP/SFTP code with catch (
FtpException), check the exception's
Status if it occurs and remove the
CheckConnectionState calls completely? The code would stay cleaner that way and should be more reliable that way.