fix by Immanuel Gregoire, sizeof != strlen!
This commit is contained in:
parent
5a854cfb26
commit
5d91d286f1
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: scp_nonblock.c,v 1.9 2007/08/09 01:10:11 dfandrich Exp $
|
* $Id: scp_nonblock.c,v 1.10 2007/09/24 12:14:18 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SCP transfers in a non-blocking manner.
|
* Sample showing how to do SCP transfers in a non-blocking manner.
|
||||||
*/
|
*/
|
||||||
@ -156,11 +156,12 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "libssh2_scp_recv() is done, now receive data!\n");
|
fprintf(stderr, "libssh2_scp_recv() is done, now receive data!\n");
|
||||||
|
|
||||||
while(got < fileinfo.st_size) {
|
while(got < fileinfo.st_size) {
|
||||||
char mem[1000];
|
char mem[256000];
|
||||||
|
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
int rc;
|
int rc;
|
||||||
fd_set fd;
|
fd_set readfd;
|
||||||
|
fd_set writefd;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int amount=sizeof(mem);
|
int amount=sizeof(mem);
|
||||||
@ -172,32 +173,56 @@ int main(int argc, char *argv[])
|
|||||||
/* loop until we block */
|
/* loop until we block */
|
||||||
rc = libssh2_channel_read(channel, mem, amount);
|
rc = libssh2_channel_read(channel, mem, amount);
|
||||||
if (rc > 0) {
|
if (rc > 0) {
|
||||||
|
#if 0
|
||||||
write(1, mem, rc);
|
write(1, mem, rc);
|
||||||
|
#endif
|
||||||
got += rc;
|
got += rc;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
//printf("libssh2 returned %d\n", rc);
|
||||||
|
}
|
||||||
} while (rc > 0);
|
} while (rc > 0);
|
||||||
|
|
||||||
if (rc == LIBSSH2_ERROR_EAGAIN) {
|
if (rc == LIBSSH2_ERROR_EAGAIN) {
|
||||||
/* this is due to blocking that would occur otherwise
|
/* this is due to blocking that would occur otherwise
|
||||||
so we loop on this condition */
|
so we loop on this condition */
|
||||||
|
|
||||||
timeout.tv_sec = 10;
|
timeout.tv_sec = 1;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
FD_ZERO(&fd);
|
FD_ZERO(&readfd);
|
||||||
|
FD_ZERO(&writefd);
|
||||||
|
|
||||||
FD_SET(sock, &fd);
|
FD_SET(sock, &readfd);
|
||||||
|
FD_SET(sock, &writefd);
|
||||||
|
|
||||||
rc = select(sock+1, &fd, &fd, NULL, &timeout);
|
rc = select(sock+1, &readfd, &writefd, NULL, &timeout);
|
||||||
if (rc <= 0) {
|
if(rc < 0) {
|
||||||
/* negative is error
|
fprintf(stderr, "SCP ERROR: %d\n", rc);
|
||||||
0 is timeout */
|
}
|
||||||
|
else if (rc == 0) {
|
||||||
fprintf(stderr, "SCP timed out: %d\n", rc);
|
fprintf(stderr, "SCP timed out: %d\n", rc);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
#if 0
|
||||||
|
if(FD_ISSET(sock, &readfd)) {
|
||||||
|
printf("Readable socket\n");
|
||||||
|
}
|
||||||
|
else if(FD_ISSET(sock, &writefd)) {
|
||||||
|
static counter=0;
|
||||||
|
printf("Writeable socket\n");
|
||||||
|
if(counter++ > 200)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
printf("Got totally %d bytes\n", (int)got);
|
||||||
|
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
channel = NULL;
|
channel = NULL;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: sftp.c,v 1.13 2007/08/09 01:10:11 dfandrich Exp $
|
* $Id: sftp.c,v 1.14 2007/09/24 12:14:18 bagder Exp $
|
||||||
*
|
*
|
||||||
* Sample showing how to do SFTP transfers.
|
* Sample showing how to do SFTP transfers.
|
||||||
*
|
*
|
||||||
@ -147,7 +147,7 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
/* check what authentication methods are available */
|
/* check what authentication methods are available */
|
||||||
userauthlist = libssh2_userauth_list(session, username, sizeof(username));
|
userauthlist = libssh2_userauth_list(session, username, strlen(username));
|
||||||
printf("Authentication methods: %s\n", userauthlist);
|
printf("Authentication methods: %s\n", userauthlist);
|
||||||
if (strstr(userauthlist, "password") != NULL) {
|
if (strstr(userauthlist, "password") != NULL) {
|
||||||
auth_pw |= 1;
|
auth_pw |= 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user