=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/sftp-client.c,v retrieving revision 1.11.2.2 retrieving revision 1.12 diff -u -r1.11.2.2 -r1.12 --- src/usr.bin/ssh/sftp-client.c 2001/03/21 18:53:04 1.11.2.2 +++ src/usr.bin/ssh/sftp-client.c 2001/03/13 22:42:54 1.12 @@ -29,7 +29,7 @@ /* XXX: copy between two remote sites */ #include "includes.h" -RCSID("$OpenBSD: sftp-client.c,v 1.11.2.2 2001/03/21 18:53:04 jason Exp $"); +RCSID("$OpenBSD: sftp-client.c,v 1.12 2001/03/13 22:42:54 djm Exp $"); #include "ssh.h" #include "buffer.h" @@ -77,9 +77,7 @@ unsigned char buf[4096]; len = atomicio(read, fd, buf, 4); - if (len == 0) - fatal("Connection closed"); - else if (len == -1) + if (len != 4) fatal("Couldn't read packet: %s", strerror(errno)); msg_len = GET_32BIT(buf); @@ -88,9 +86,7 @@ while (msg_len) { len = atomicio(read, fd, buf, MIN(msg_len, sizeof(buf))); - if (len == 0) - fatal("Connection closed"); - else if (len == -1) + if (len <= 0) fatal("Couldn't read packet: %s", strerror(errno)); msg_len -= len; @@ -184,7 +180,7 @@ } Attrib * -get_decode_stat(int fd, u_int expected_id, int quiet) +get_decode_stat(int fd, u_int expected_id) { Buffer msg; u_int type, id; @@ -202,10 +198,7 @@ if (type == SSH2_FXP_STATUS) { int status = buffer_get_int(&msg); - if (quiet) - debug("Couldn't stat remote file: %s", fx2txt(status)); - else - error("Couldn't stat remote file: %s", fx2txt(status)); + error("Couldn't stat remote file: %s", fx2txt(status)); return(NULL); } else if (type != SSH2_FXP_ATTRS) { fatal("Expected SSH2_FXP_ATTRS(%d) packet, got %d", @@ -288,7 +281,7 @@ SFTP_DIRENT ***dir) { Buffer msg; - u_int type, id, handle_len, i, expected_id, ents = 0; + u_int type, id, handle_len, i, expected_id, ents; char *handle; id = msg_id++; @@ -462,33 +455,34 @@ } Attrib * -do_stat(int fd_in, int fd_out, char *path, int quiet) +do_stat(int fd_in, int fd_out, char *path) { u_int id; id = msg_id++; send_string_request(fd_out, id, SSH2_FXP_STAT, path, strlen(path)); - return(get_decode_stat(fd_in, id, quiet)); + return(get_decode_stat(fd_in, id)); } Attrib * -do_lstat(int fd_in, int fd_out, char *path, int quiet) +do_lstat(int fd_in, int fd_out, char *path) { u_int id; id = msg_id++; send_string_request(fd_out, id, SSH2_FXP_LSTAT, path, strlen(path)); - return(get_decode_stat(fd_in, id, quiet)); + return(get_decode_stat(fd_in, id)); } Attrib * -do_fstat(int fd_in, int fd_out, char *handle, u_int handle_len, int quiet) +do_fstat(int fd_in, int fd_out, char *handle, + u_int handle_len) { u_int id; id = msg_id++; send_string_request(fd_out, id, SSH2_FXP_FSTAT, handle, handle_len); - return(get_decode_stat(fd_in, id, quiet)); + return(get_decode_stat(fd_in, id)); } int @@ -683,7 +677,7 @@ Attrib junk, *a; int status; - a = do_stat(fd_in, fd_out, remote_path, 0); + a = do_stat(fd_in, fd_out, remote_path); if (a == NULL) return(-1); @@ -693,17 +687,11 @@ else mode = 0666; - if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) && - (a->perm & S_IFDIR)) { - error("Cannot download a directory: %s", remote_path); - return(-1); - } - local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, mode); if (local_fd == -1) { error("Couldn't open local file \"%s\" for writing: %s", local_path, strerror(errno)); - return(-1); + return(errno); } buffer_init(&msg);