aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2009-10-29 10:50:47 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2009-10-29 10:50:47 +0100
commite455f6f756fd6e3c8d112d3ee0190b91c1efb7e4 (patch)
tree5ce7db0f1cd291445d6b72e46fe8d17a47f93b07
parent17f2645a32e6524c36b2f83831080eda378c12bf (diff)
downloadlibssh-e455f6f756fd6e3c8d112d3ee0190b91c1efb7e4.tar.gz
libssh-e455f6f756fd6e3c8d112d3ee0190b91c1efb7e4.tar.xz
libssh-e455f6f756fd6e3c8d112d3ee0190b91c1efb7e4.zip
Make libssh_scp a little more consistant
-rw-r--r--examples/libssh_scp.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/examples/libssh_scp.c b/examples/libssh_scp.c
index 5d92e3c..83e60b5 100644
--- a/examples/libssh_scp.c
+++ b/examples/libssh_scp.c
@@ -175,6 +175,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
int total=0;
int mode;
char *filename;
+ /* recursive mode doesn't work yet */
(void)recursive;
/* Get the file name and size*/
if(!src->is_ssh){
@@ -263,26 +264,14 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
total+=r;
} while(total < size);
- printf("wrote %d bytes\n",total);
- if(dest->is_ssh){
- r=ssh_scp_close(dest->scp);
- if(r == SSH_ERROR){
- fprintf(stderr,"Error closing scp: %s\n",ssh_get_error(dest->session));
- ssh_scp_free(dest->scp);
- dest->scp=NULL;
- return -1;
- }
- } else {
- fclose(dest->file);
- dest->file=NULL;
- }
- return 0;
+ printf("wrote %d bytes\n",total);
+ return 0;
}
int main(int argc, char **argv){
struct location *dest, *src;
int i;
-
+ int r;
if(opts(argc,argv)<0)
return EXIT_FAILURE;
dest=parse_location(destination);
@@ -293,12 +282,22 @@ int main(int argc, char **argv){
if(open_location(src,READ)<0){
return EXIT_FAILURE;
}
- while(1){
- if(do_copy(src,dest,0) < 0){
- break;
- }
+ if(do_copy(src,dest,0) < 0){
+ break;
}
}
+ if(dest->is_ssh){
+ r=ssh_scp_close(dest->scp);
+ if(r == SSH_ERROR){
+ fprintf(stderr,"Error closing scp: %s\n",ssh_get_error(dest->session));
+ ssh_scp_free(dest->scp);
+ dest->scp=NULL;
+ return -1;
+ }
+ } else {
+ fclose(dest->file);
+ dest->file=NULL;
+ }
ssh_disconnect(dest->session);
ssh_finalize();
return 0;