Subject: libssh2_channel_read example

libssh2_channel_read example

From: vicent roca daniel <>
Date: Sun, 26 Feb 2012 12:57:37 +0100

Hi guys,
I'm having problems getting to work properly the function
libssh2_channel_read, this is an example code of what I'm doing:

/* vars def */
int rc = 0;
char buffer2[1024*4];
FILE *file;

file = fopen("somefile.txt, "w");

/* reopen the channel for the new command */

/* execute command */
rc = libssh2_channel_exec(channel, "/bin/ssh_command argument1");

 while( (read = libssh2_channel_read( channel, buffer2, sizeof(buffer2))) >
0 )
        fwrite(buffer2, sizeof(char), read, file);

fclose( file );

I Don't know if this way of reading an ssh command output, and dumping to a
file is correct, becouse I'm getting some segmentation fails forward in the
code, and I suspect It came from here....

Anu hints are very welcome! Thanks :)

Received on 2012-02-26