Description
| Returns 1 if connected to the SSH server. Note: This does not mean authentication has happened or InitializeSftp has already succeeded. It only means that the connection has been established by calling Connect.
Understanding the IsConnected property: The IsConnected property is the last known state of the TCP connection (either connected or disconnected). This requires some explanation because most developer have incorrect assumptions about TCP connections.
- If a TCP connection is established, and neither side is reading or writing the socket (i.e. both sides are doing nothing), then you can disconnect the network cable from the computer for any length of time, and then re-connect, and the TCP connection is not affected.
- A TCP connection only becomes disconnected when an attempt is made to read/write while a network problem exists. If no attempts to read/write occur, a network problem may arise and then become resolved without affecting the TCP connection.
- If the peer chooses to close its side of the TCP connection, your application won't magically know about it until you try to do something with the TCP socket (such as read or write).
- A Chilkat API property (as opposed to a method) CANNOT and should not do something that would cause an application to timeout, hang, etc. Therefore, it is not appropriate for the IsConnected property to attempt any kind of socket operation (read/write/peek) on the socket. It simply returns the last known state of the connection. It may very well be that your network cable is unplugged and IsConnected returns 1 because technically, if neither peer is trying to read/write, the network cable could be plugged back in without affecting the connection. IsConnected could also return 1 if the peer has already closed its side of the connection, because the state of the connection is only updated after trying to read/write/peek.
- To truly know the current connected state (as opposed to the last known connection state), your application should attempt a network operation that is appropriate to the protocol. For SFTP, an application could call SendIgnore, and then check IsConnected.
|