Chris Nystrom helped me realize I must count the received bytes myself to
know when the transfer is complete
This commit is contained in:
parent
5859642888
commit
09ee2d4086
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: scp.c,v 1.2 2007/01/30 11:10:26 bagder Exp $
|
* $Id: scp.c,v 1.3 2007/02/01 22:39:45 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do a simple SCP transfer.
|
* Sample showing how to do a simple SCP transfer.
|
||||||
*/
|
*/
|
||||||
@ -32,6 +32,7 @@ int main(int argc, char *argv[])
|
|||||||
char *scppath=(char *)"/tmp/TEST";
|
char *scppath=(char *)"/tmp/TEST";
|
||||||
struct stat fileinfo;
|
struct stat fileinfo;
|
||||||
int rc;
|
int rc;
|
||||||
|
off_t got=0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
WSADATA wsadata;
|
WSADATA wsadata;
|
||||||
@ -116,16 +117,26 @@ int main(int argc, char *argv[])
|
|||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
|
||||||
|
while(got < fileinfo.st_size) {
|
||||||
char mem[1024];
|
char mem[1024];
|
||||||
/* loop until we fail */
|
int amount=sizeof(mem);
|
||||||
rc = libssh2_channel_read(channel, mem, sizeof(mem));
|
|
||||||
fprintf(stderr, "libssh2_channel_read returned %d\n",
|
if((fileinfo.st_size -got) < amount) {
|
||||||
rc);
|
amount = fileinfo.st_size -got;
|
||||||
if(rc > 0) {
|
}
|
||||||
|
|
||||||
|
rc = libssh2_channel_read(channel, mem, amount);
|
||||||
|
if(rc == amount) {
|
||||||
write(2, mem, rc);
|
write(2, mem, rc);
|
||||||
}
|
}
|
||||||
} while (rc > 0);
|
else {
|
||||||
|
fprintf(stderr, "libssh2_channel_read() failed: %d\n",
|
||||||
|
rc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
got += rc;
|
||||||
|
}
|
||||||
|
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
channel = NULL;
|
channel = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user