diff options
Diffstat (limited to 'sftp-client.c')
-rw-r--r-- | sftp-client.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/sftp-client.c b/sftp-client.c index 87f3053f6..b0007a734 100644 --- a/sftp-client.c +++ b/sftp-client.c | |||
@@ -29,7 +29,7 @@ | |||
29 | /* XXX: copy between two remote sites */ | 29 | /* XXX: copy between two remote sites */ |
30 | 30 | ||
31 | #include "includes.h" | 31 | #include "includes.h" |
32 | RCSID("$OpenBSD: sftp-client.c,v 1.13 2001/03/14 08:57:14 markus Exp $"); | 32 | RCSID("$OpenBSD: sftp-client.c,v 1.14 2001/03/16 08:16:17 djm Exp $"); |
33 | 33 | ||
34 | #include "ssh.h" | 34 | #include "ssh.h" |
35 | #include "buffer.h" | 35 | #include "buffer.h" |
@@ -180,7 +180,7 @@ get_handle(int fd, u_int expected_id, u_int *len) | |||
180 | } | 180 | } |
181 | 181 | ||
182 | Attrib * | 182 | Attrib * |
183 | get_decode_stat(int fd, u_int expected_id) | 183 | get_decode_stat(int fd, u_int expected_id, int quiet) |
184 | { | 184 | { |
185 | Buffer msg; | 185 | Buffer msg; |
186 | u_int type, id; | 186 | u_int type, id; |
@@ -198,7 +198,10 @@ get_decode_stat(int fd, u_int expected_id) | |||
198 | if (type == SSH2_FXP_STATUS) { | 198 | if (type == SSH2_FXP_STATUS) { |
199 | int status = buffer_get_int(&msg); | 199 | int status = buffer_get_int(&msg); |
200 | 200 | ||
201 | error("Couldn't stat remote file: %s", fx2txt(status)); | 201 | if (quiet) |
202 | debug("Couldn't stat remote file: %s", fx2txt(status)); | ||
203 | else | ||
204 | error("Couldn't stat remote file: %s", fx2txt(status)); | ||
202 | return(NULL); | 205 | return(NULL); |
203 | } else if (type != SSH2_FXP_ATTRS) { | 206 | } else if (type != SSH2_FXP_ATTRS) { |
204 | fatal("Expected SSH2_FXP_ATTRS(%d) packet, got %d", | 207 | fatal("Expected SSH2_FXP_ATTRS(%d) packet, got %d", |
@@ -455,34 +458,33 @@ do_rmdir(int fd_in, int fd_out, char *path) | |||
455 | } | 458 | } |
456 | 459 | ||
457 | Attrib * | 460 | Attrib * |
458 | do_stat(int fd_in, int fd_out, char *path) | 461 | do_stat(int fd_in, int fd_out, char *path, int quiet) |
459 | { | 462 | { |
460 | u_int id; | 463 | u_int id; |
461 | 464 | ||
462 | id = msg_id++; | 465 | id = msg_id++; |
463 | send_string_request(fd_out, id, SSH2_FXP_STAT, path, strlen(path)); | 466 | send_string_request(fd_out, id, SSH2_FXP_STAT, path, strlen(path)); |
464 | return(get_decode_stat(fd_in, id)); | 467 | return(get_decode_stat(fd_in, id, quiet)); |
465 | } | 468 | } |
466 | 469 | ||
467 | Attrib * | 470 | Attrib * |
468 | do_lstat(int fd_in, int fd_out, char *path) | 471 | do_lstat(int fd_in, int fd_out, char *path, int quiet) |
469 | { | 472 | { |
470 | u_int id; | 473 | u_int id; |
471 | 474 | ||
472 | id = msg_id++; | 475 | id = msg_id++; |
473 | send_string_request(fd_out, id, SSH2_FXP_LSTAT, path, strlen(path)); | 476 | send_string_request(fd_out, id, SSH2_FXP_LSTAT, path, strlen(path)); |
474 | return(get_decode_stat(fd_in, id)); | 477 | return(get_decode_stat(fd_in, id, quiet)); |
475 | } | 478 | } |
476 | 479 | ||
477 | Attrib * | 480 | Attrib * |
478 | do_fstat(int fd_in, int fd_out, char *handle, | 481 | do_fstat(int fd_in, int fd_out, char *handle, u_int handle_len, int quiet) |
479 | u_int handle_len) | ||
480 | { | 482 | { |
481 | u_int id; | 483 | u_int id; |
482 | 484 | ||
483 | id = msg_id++; | 485 | id = msg_id++; |
484 | send_string_request(fd_out, id, SSH2_FXP_FSTAT, handle, handle_len); | 486 | send_string_request(fd_out, id, SSH2_FXP_FSTAT, handle, handle_len); |
485 | return(get_decode_stat(fd_in, id)); | 487 | return(get_decode_stat(fd_in, id, quiet)); |
486 | } | 488 | } |
487 | 489 | ||
488 | int | 490 | int |
@@ -677,7 +679,7 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | |||
677 | Attrib junk, *a; | 679 | Attrib junk, *a; |
678 | int status; | 680 | int status; |
679 | 681 | ||
680 | a = do_stat(fd_in, fd_out, remote_path); | 682 | a = do_stat(fd_in, fd_out, remote_path, 0); |
681 | if (a == NULL) | 683 | if (a == NULL) |
682 | return(-1); | 684 | return(-1); |
683 | 685 | ||
@@ -687,11 +689,17 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | |||
687 | else | 689 | else |
688 | mode = 0666; | 690 | mode = 0666; |
689 | 691 | ||
692 | if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && | ||
693 | (a->perm & S_IFDIR)) { | ||
694 | error("Cannot download a directory: %s", remote_path); | ||
695 | return(-1); | ||
696 | } | ||
697 | |||
690 | local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, mode); | 698 | local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, mode); |
691 | if (local_fd == -1) { | 699 | if (local_fd == -1) { |
692 | error("Couldn't open local file \"%s\" for writing: %s", | 700 | error("Couldn't open local file \"%s\" for writing: %s", |
693 | local_path, strerror(errno)); | 701 | local_path, strerror(errno)); |
694 | return(errno); | 702 | return(-1); |
695 | } | 703 | } |
696 | 704 | ||
697 | buffer_init(&msg); | 705 | buffer_init(&msg); |