FileTransferClient disconnected event?

0 votes
asked Jul 6 by rexh (520 points)

How come there isn't an event for disconnection from an ftp server?

We have a button to allow the user to connect/disconnect from an ftp server and we want the button to also reflect the current state of connection. As soon as the host has disconnected, we want to uncheck the button.

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Jul 7 by Lukas Pokorny (115,410 points)
selected Jul 8 by rexh
 
Best answer

For a Disconnected event to really be usable, it would also have to be raised on connection failures, and the only way to reliably detect that is to periodically send a small chunk of data over the connection while idle. That's an action we would rather not be doing automatically, so we decided against adding the Disconnected event.

Instead, the recommended way to detect disconnection (including connection failure) is to periodically call FileTransferClient's KeepAlive() method while idle - if it fails, it means the connection has been disconnected or failed. To find out more about the failure reason, check the contents of NetworkSessionException (FtpException for FTP protocol, SftpException for SFTP protocol).

commented Jul 8 by rexh (520 points)
edited Jul 8 by rexh
Thank you for the detailed explanation.
Should I call the CheckConnectionState instead if I don't want to have the keep alives sent?

Another question is, when the server (FileZilla) shuts down, how come we are not getting the "421 Server is going offline" from the logger.
...