diff options
author | Damien Miller <djm@mindrot.org> | 2002-02-08 22:04:05 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2002-02-08 22:04:05 +1100 |
commit | 8829d3669d154dbd06f9ee2cc779f14e2af8e15f (patch) | |
tree | 06c5dc3d5c2352c1466d76512d2d9cd5e6b6513a /sftp-client.c | |
parent | e8c9ed436a23d0fdbad1881092a3f9d2e7d5f822 (diff) |
- djm@cvs.openbsd.org 2002/02/05 00:00:46
[sftp.1 sftp.c sftp-client.c sftp-client.h sftp-int.c]
Add "-B" option to specify copy buffer length (default 32k); ok markus@
Diffstat (limited to 'sftp-client.c')
-rw-r--r-- | sftp-client.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/sftp-client.c b/sftp-client.c index ca5a48597..362814d42 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.19 2001/12/19 07:18:56 deraadt Exp $"); | 32 | RCSID("$OpenBSD: sftp-client.c,v 1.20 2002/02/05 00:00:46 djm Exp $"); |
33 | 33 | ||
34 | #include "buffer.h" | 34 | #include "buffer.h" |
35 | #include "bufaux.h" | 35 | #include "bufaux.h" |
@@ -42,10 +42,6 @@ RCSID("$OpenBSD: sftp-client.c,v 1.19 2001/12/19 07:18:56 deraadt Exp $"); | |||
42 | #include "sftp-common.h" | 42 | #include "sftp-common.h" |
43 | #include "sftp-client.h" | 43 | #include "sftp-client.h" |
44 | 44 | ||
45 | /* How much data to read/write at at time during copies */ | ||
46 | /* XXX: what should this be? */ | ||
47 | #define COPY_SIZE 8192 | ||
48 | |||
49 | /* Message ID */ | 45 | /* Message ID */ |
50 | static u_int msg_id = 1; | 46 | static u_int msg_id = 1; |
51 | 47 | ||
@@ -670,15 +666,14 @@ do_readlink(int fd_in, int fd_out, char *path) | |||
670 | 666 | ||
671 | int | 667 | int |
672 | do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | 668 | do_download(int fd_in, int fd_out, char *remote_path, char *local_path, |
673 | int pflag) | 669 | int pflag, size_t buflen) |
674 | { | 670 | { |
675 | int local_fd; | 671 | int local_fd, status; |
676 | u_int expected_id, handle_len, mode, type, id; | 672 | u_int expected_id, handle_len, mode, type, id; |
677 | u_int64_t offset; | 673 | u_int64_t offset; |
678 | char *handle; | 674 | char *handle; |
679 | Buffer msg; | 675 | Buffer msg; |
680 | Attrib junk, *a; | 676 | Attrib junk, *a; |
681 | int status; | ||
682 | 677 | ||
683 | a = do_stat(fd_in, fd_out, remote_path, 0); | 678 | a = do_stat(fd_in, fd_out, remote_path, 0); |
684 | if (a == NULL) | 679 | if (a == NULL) |
@@ -736,10 +731,10 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | |||
736 | buffer_put_int(&msg, id); | 731 | buffer_put_int(&msg, id); |
737 | buffer_put_string(&msg, handle, handle_len); | 732 | buffer_put_string(&msg, handle, handle_len); |
738 | buffer_put_int64(&msg, offset); | 733 | buffer_put_int64(&msg, offset); |
739 | buffer_put_int(&msg, COPY_SIZE); | 734 | buffer_put_int(&msg, buflen); |
740 | send_msg(fd_out, &msg); | 735 | send_msg(fd_out, &msg); |
741 | debug3("Sent message SSH2_FXP_READ I:%d O:%llu S:%u", | 736 | debug3("Sent message SSH2_FXP_READ I:%d O:%llu S:%u", |
742 | id, (u_int64_t)offset, COPY_SIZE); | 737 | id, (u_int64_t)offset, buflen); |
743 | 738 | ||
744 | buffer_clear(&msg); | 739 | buffer_clear(&msg); |
745 | 740 | ||
@@ -767,9 +762,9 @@ do_download(int fd_in, int fd_out, char *remote_path, char *local_path, | |||
767 | } | 762 | } |
768 | 763 | ||
769 | data = buffer_get_string(&msg, &len); | 764 | data = buffer_get_string(&msg, &len); |
770 | if (len > COPY_SIZE) | 765 | if (len > buflen) |
771 | fatal("Received more data than asked for %d > %d", | 766 | fatal("Received more data than asked for %d > %d", |
772 | len, COPY_SIZE); | 767 | len, buflen); |
773 | 768 | ||
774 | debug3("In read loop, got %d offset %llu", len, | 769 | debug3("In read loop, got %d offset %llu", len, |
775 | (u_int64_t)offset); | 770 | (u_int64_t)offset); |
@@ -814,16 +809,15 @@ done: | |||
814 | 809 | ||
815 | int | 810 | int |
816 | do_upload(int fd_in, int fd_out, char *local_path, char *remote_path, | 811 | do_upload(int fd_in, int fd_out, char *local_path, char *remote_path, |
817 | int pflag) | 812 | int pflag, size_t buflen) |
818 | { | 813 | { |
819 | int local_fd; | 814 | int local_fd, status; |
820 | u_int handle_len, id; | 815 | u_int handle_len, id; |
821 | u_int64_t offset; | 816 | u_int64_t offset; |
822 | char *handle; | 817 | char *handle, *data; |
823 | Buffer msg; | 818 | Buffer msg; |
824 | struct stat sb; | 819 | struct stat sb; |
825 | Attrib a; | 820 | Attrib a; |
826 | int status; | ||
827 | 821 | ||
828 | if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) { | 822 | if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) { |
829 | error("Couldn't open local file \"%s\" for reading: %s", | 823 | error("Couldn't open local file \"%s\" for reading: %s", |
@@ -865,18 +859,19 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path, | |||
865 | return(-1); | 859 | return(-1); |
866 | } | 860 | } |
867 | 861 | ||
862 | data = xmalloc(buflen); | ||
863 | |||
868 | /* Read from local and write to remote */ | 864 | /* Read from local and write to remote */ |
869 | offset = 0; | 865 | offset = 0; |
870 | for (;;) { | 866 | for (;;) { |
871 | int len; | 867 | int len; |
872 | char data[COPY_SIZE]; | ||
873 | 868 | ||
874 | /* | 869 | /* |
875 | * Can't use atomicio here because it returns 0 on EOF, thus losing | 870 | * Can't use atomicio here because it returns 0 on EOF, thus losing |
876 | * the last block of the file | 871 | * the last block of the file |
877 | */ | 872 | */ |
878 | do | 873 | do |
879 | len = read(local_fd, data, COPY_SIZE); | 874 | len = read(local_fd, data, buflen); |
880 | while ((len == -1) && (errno == EINTR || errno == EAGAIN)); | 875 | while ((len == -1) && (errno == EINTR || errno == EAGAIN)); |
881 | 876 | ||
882 | if (len == -1) | 877 | if (len == -1) |
@@ -908,6 +903,7 @@ do_upload(int fd_in, int fd_out, char *local_path, char *remote_path, | |||
908 | 903 | ||
909 | offset += len; | 904 | offset += len; |
910 | } | 905 | } |
906 | xfree(data); | ||
911 | 907 | ||
912 | if (close(local_fd) == -1) { | 908 | if (close(local_fd) == -1) { |
913 | error("Couldn't close local file \"%s\": %s", local_path, | 909 | error("Couldn't close local file \"%s\": %s", local_path, |