Subject: How to use libssh2_channel_write()

How to use libssh2_channel_write()

From: dfg dfg <abxccd_at_msn.com>
Date: Sat, 4 Sep 2010 02:00:31 +0000

Hi all,

 

I would like to know how to use the libssh2_channel_write() command to write a command to a shell. My code is copied from: http://www.libssh2.org/examples/ssh2.html

 

I have accquired a shell and a pty. In the sample code, there is the following comment:

 

  /* At this point the shell can be interacted with using
     * libssh2_channel_read()
     * libssh2_channel_read_stderr()
     * libssh2_channel_write()
     * libssh2_channel_write_stderr()
     *
     * Blocking mode may be (en|dis)abled with: libssh2_channel_set_blocking()
     * If the server send EOF, libssh2_channel_eof() will return non-0
     * To send EOF to the server use: libssh2_channel_send_eof()
     * A channel can be closed with: libssh2_channel_close()
     * A channel can be freed with: libssh2_channel_free()
     */

I then attempted to use libssh2_channel_write() to send a command. Here's what I've done:

 

int rc = 0;
char command[50] = "mkdir ~/testfolder\n";

rc = libssh2_channel_write(channel, command, sizeof(command));
fprintf(stderr, "bytes written %d\n", rc);

libssh2_channel_send_eof(channel);

 

I get a positive number of bytes written. However the command never executes (the folder is not created). Can any one tell me what went wrong?

 

Thanks!
                                               

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-09-04