Barry, Mike wrote:
> 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.
Please note that there is a world of difference between SCP and SFTP.
Remember to be clear about what you are using.
> 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" );
> }
> Any pointers? Or ideas?
> ....
Your code should work. It needs the server to allow creating more
than one channel per session. Generally that should not be a problem,
but since you meantion this is only an issue with some SSH servers,
maybe you are running into some implementation specific server-side
limitations?
Can you do testing also with other clients?
Note also that SFTP should be STRONGLY favored over SCP for any file
transfer related activity. Using SFTP you can also do multiple
operations using only a single (subsystem) channel.
SCP on the other hand needs to execute the scp program, in a new
channel, for each scp operation.
//Peter
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel