[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: which LibSSH API notifies Client if Server gets Disconnected.


On 2/17/20 2:43 PM, V Sidnal, Nagraju wrote:
Dear Team,

We are using below logic to execute command on SSH Server.

   int rc = ssh_connect(my_ssh_session);

   rc = ssh_pki_import_privkey_file("id_rsa", NULL, NULL, NULL, &pkey);

   rc = ssh_userauth_publickey(my_ssh_session, NULL, pkey);

   channel = ssh_channel_new(my_ssh_session);

   rc = ssh_channel_open_session(channel);

   rc = ssh_channel_request_exec(channel, "lscommand");

//after this we reading the result & closing the channel.

We are keeping session saved in our class for next command execution/call iteration, so that we don’t need to create connection again.

However For next call, every time we are creating new channel for executing the command, as we cannot use same channel.

We are running some logic internally, which keeps checking  ssh_is_connected() , to keep track of connection status with Server.

However this logic looks heavy.

Could you please help me with the API of libssh – callback API’s of libssh, using which I don’t need to check ssh_is_connected().

I’m unable to figure out a Call back Api , using which Client will get notified whenever server gets disconnected.

Hello,
There is no straight-forward callback API to notify you about disconnect asynchronously as this disconnect can happen for various reason from software failure, software disconnect, network failure, timeouts and so on.

Generally, you don't know if the remote is connected before you try to write anything to the channel, either directly the channel request or using (periodic) keekapive message (this was recently discussed on this mailing list.

Regards,
--
Jakub Jelen
Senior Software Engineer
Crypto Team, Security Engineering
Red Hat, Inc.


Archive administrator: postmaster@lists.cynapses.org