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

using ssh_channel_write for command execution problem

Hi all,

I am trying to establish a persistent connection to a SSH server where I
want to periodically send commands via ssh_channel_write. I am using Linux
(5.0.0-32-generic #34~18.04.2-Ubuntu SMP).

My problem is when I call ssh_channel_write with a command I sometimes see
it executed on the server and sometimes not (but I think I don't have any
errors in logs). I am not sure what I am doing wrong. My code is very
simple and looks like this (for brevity I didn't include checking/error
handling, but I triple checked every call, they are all fine):

    ssh_session session = ssh_new();
    ssh_channel channel = nullptr;

    ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
    int verb = SSH_LOG_FUNCTIONS;
    int port = 22;
    ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verb);
    ssh_options_set(session, SSH_OPTIONS_PORT, &port);


    ssh_userauth_password(session, "karah", "password");

    channel = ssh_channel_new(session);
    ssh_channel_change_pty_size(channel, 220, 220);
    char cmd[] = "touch ~/abcde\n"; //dummy command

    ssh_channel_write(channel, cmd, sizeof(cmd)); //I would like to call
this many times during the lifetime of channel
    ssh_blocking_flush(session, -1);

In the attachment I am adding the SSH_LOG_FUNCTIONS output. If I brute
force the ssh_channel_write in an endless while loop like this:

        ssh_channel_write(channel, cmd, sizeof(cmd));

it eventually gets executed on the server. So I know the connection is ok
and probably I am calling the API in a wrong way.

I am obviously doing something wrong but I can't figure out what. Maybe I
am using the API in a wrong way or I misunderstood some key concept, I
don't know. Any help or hint would be highly appreciated.


Attachment: logs
Description: Binary data

Re: using ssh_channel_write for command execution problemAndreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org