Ftp
object's CheckConnectionState method only throws an exception if the connection is already known to have ended when the method is called. If the client machine is not yet aware that the connection has been lost, the method will return without raising an exception.
The only reliable way to determine whether the connection is still active is to send a command over it - if the connection has already been lost, it won't be possible to transmit the command to the server and the connection will be acknowledged as disconnected. In case of FTP, the KeepAlive
or GetCurrentDirectory
methods can be used for this purpose.
This said, it is a bit strange that CheckConnectionState
can't detect a manually closed connection in this case. That kind of action should gracefully close the connection, making the client aware of it immediately, causing the CheckConnectionState
method to fail. We will try to reproduce this problem ourselves. Until then, using one of the methods that actually send some command (see above) is recommended.