0 votes
by (600 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
by (146k points)
selected by
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).

by (600 points)
edited by
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.