Hi all,
I am currently writing a program that will use libssh2 on Ubuntu 10.04. To make sure I have SSH working, I installed openssh-server and tested it by connecting to it. I also successfully SCP'd a file to the server using the "scp" command.
I then did a small test by using libssh2 to connect to the ssh server, open a ssh channel and run a command such as "uptime". This all worked perfectly.
However, I ran into a problem when trying to send a file using SCP. I have followed the example code here: http://www.libssh2.org/examples/scp_write.html
The code was copied and pasted from that example. I was successful in connecting to the SSH server and logging in. But, I seem to get an error when opening the SCP channel.
The code to do so is the following:
/* Send a file via scp. The mode parameter must only have permissions! */
channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777, (unsigned long)fileinfo.st_size);
if (!channel) {
char *errmsg;
int errlen;
int err = libssh2_session_last_error(session, &errmsg, &errlen, 0);
fprintf(stderr, "Unable to open a session: (%d) %s\n", err, errmsg);
goto shutdown;
}
This returns an error: Unable to open a session: (0)
I am not sure what is meant by the error code 0. I also thought it was a bit weird that there was no error message set into err msg.
If I do comment out the lines that checks whether the channel has been set, I get another error from this block of code:
do {
nread = fread(mem, 1, sizeof(mem), local);
if (nread <= 0) {
/* end of file */
break;
}
ptr = mem;
do {
/* write the same data over and over, until error or completion */
rc = libssh2_channel_write(channel, ptr, nread);
if (rc < 0) {
fprintf(stderr, "ERROR %d\n", rc);
break;
}
else {
/* rc indicates how many bytes were written this time */
ptr += rc;
nread -= rc;
}
} while (nread);
} while (1);
I get the error: ERROR -39
Can anyone please assist me and tell me what I have done wrong?
Thank you very much :)
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-09-04