1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

Make libssh_scp a little more consistant

This commit is contained in:
Aris Adamantiadis
2009-10-29 10:50:47 +01:00
parent 17f2645a32
commit e455f6f756

View File

@ -175,6 +175,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
int total=0; int total=0;
int mode; int mode;
char *filename; char *filename;
/* recursive mode doesn't work yet */
(void)recursive; (void)recursive;
/* Get the file name and size*/ /* Get the file name and size*/
if(!src->is_ssh){ if(!src->is_ssh){
@ -264,6 +265,27 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
} while(total < size); } while(total < size);
printf("wrote %d bytes\n",total); 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);
if(open_location(dest,WRITE)<0)
return EXIT_FAILURE;
for(i=0;i<nsources;++i){
src=parse_location(sources[i]);
if(open_location(src,READ)<0){
return EXIT_FAILURE;
}
if(do_copy(src,dest,0) < 0){
break;
}
}
if(dest->is_ssh){ if(dest->is_ssh){
r=ssh_scp_close(dest->scp); r=ssh_scp_close(dest->scp);
if(r == SSH_ERROR){ if(r == SSH_ERROR){
@ -276,29 +298,6 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
fclose(dest->file); fclose(dest->file);
dest->file=NULL; dest->file=NULL;
} }
return 0;
}
int main(int argc, char **argv){
struct location *dest, *src;
int i;
if(opts(argc,argv)<0)
return EXIT_FAILURE;
dest=parse_location(destination);
if(open_location(dest,WRITE)<0)
return EXIT_FAILURE;
for(i=0;i<nsources;++i){
src=parse_location(sources[i]);
if(open_location(src,READ)<0){
return EXIT_FAILURE;
}
while(1){
if(do_copy(src,dest,0) < 0){
break;
}
}
}
ssh_disconnect(dest->session); ssh_disconnect(dest->session);
ssh_finalize(); ssh_finalize();
return 0; return 0;