All,
I've been having an issue with sending/receiving multiple files to
certain SSH servers. The initial send/receive goes fine but when I try
the second time, I'm unable to open a new channel. I modified the
example scp.c code to do something like below. Some SFTP servers
have no problems. Others are giving me errors such as
Timed out waiting for SCP response.
Any pointers? Or ideas?
....
do_scp( session, scppath );
do_scp( session, scppath );
void do_scp( LIBSSH2_SESSION *session, char *path )
{
LIBSSH2_CHANNEL *channel;
struct stat fileinfo;
off_t got=0;
int rc;
/* Request a file via SCP */
channel = libssh2_scp_recv(session, path, &fileinfo);
if (!channel) {
char *err_msg;
libssh2_session_last_error(session, &err_msg, NULL, 0);
fprintf(stderr, "%s\n", err_msg);
fprintf(stderr, "Unable to open a session\n");
return;
}
while(got < fileinfo.st_size) {
char mem[1024];
int amount=sizeof(mem);
if((fileinfo.st_size -got) < amount) {
amount = fileinfo.st_size -got;
}
rc = libssh2_channel_read(channel, mem, amount);
if(rc == amount) {
write(1, mem, rc);
}
else {
fprintf(stderr, "libssh2_channel_read() failed: %d\n", rc);
break;
}
got += rc;
}
libssh2_channel_free(channel);
channel = NULL;
fprintf( stderr, "Retrieved file\n" );
}
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel