summaryrefslogtreecommitdiff
path: root/sftp-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp-client.c')
-rw-r--r--sftp-client.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sftp-client.c b/sftp-client.c
index bff37073c..e0d3ad568 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -28,7 +28,7 @@
28/* XXX: copy between two remote sites */ 28/* XXX: copy between two remote sites */
29 29
30#include "includes.h" 30#include "includes.h"
31RCSID("$OpenBSD: sftp-client.c,v 1.38 2003/01/06 23:51:22 djm Exp $"); 31RCSID("$OpenBSD: sftp-client.c,v 1.39 2003/01/10 08:19:07 fgsch Exp $");
32 32
33#include "openbsd-compat/sys-queue.h" 33#include "openbsd-compat/sys-queue.h"
34 34
@@ -38,11 +38,14 @@ RCSID("$OpenBSD: sftp-client.c,v 1.38 2003/01/06 23:51:22 djm Exp $");
38#include "xmalloc.h" 38#include "xmalloc.h"
39#include "log.h" 39#include "log.h"
40#include "atomicio.h" 40#include "atomicio.h"
41#include "progressmeter.h"
41 42
42#include "sftp.h" 43#include "sftp.h"
43#include "sftp-common.h" 44#include "sftp-common.h"
44#include "sftp-client.h" 45#include "sftp-client.h"
45 46
47extern int showprogress;
48
46/* Minimum amount of data to read at at time */ 49/* Minimum amount of data to read at at time */
47#define MIN_READ_SIZE 512 50#define MIN_READ_SIZE 512
48 51
@@ -741,6 +744,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
741 int read_error, write_errno; 744 int read_error, write_errno;
742 u_int64_t offset, size; 745 u_int64_t offset, size;
743 u_int handle_len, mode, type, id, buflen; 746 u_int handle_len, mode, type, id, buflen;
747 off_t progress_counter;
744 struct request { 748 struct request {
745 u_int id; 749 u_int id;
746 u_int len; 750 u_int len;
@@ -806,6 +810,16 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
806 /* Read from remote and write to local */ 810 /* Read from remote and write to local */
807 write_error = read_error = write_errno = num_req = offset = 0; 811 write_error = read_error = write_errno = num_req = offset = 0;
808 max_req = 1; 812 max_req = 1;
813 progress_counter = 0;
814
815 if (showprogress) {
816 if (size)
817 start_progress_meter(remote_path, size,
818 &progress_counter);
819 else
820 printf("Fetching %s to %s\n", remote_path, local_path);
821 }
822
809 while (num_req > 0 || max_req > 0) { 823 while (num_req > 0 || max_req > 0) {
810 char *data; 824 char *data;
811 u_int len; 825 u_int len;
@@ -866,6 +880,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
866 write_error = 1; 880 write_error = 1;
867 max_req = 0; 881 max_req = 0;
868 } 882 }
883 progress_counter += len;
869 xfree(data); 884 xfree(data);
870 885
871 if (len == req->len) { 886 if (len == req->len) {
@@ -908,6 +923,9 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path,
908 } 923 }
909 } 924 }
910 925
926 if (showprogress && size)
927 stop_progress_meter();
928
911 /* Sanity check */ 929 /* Sanity check */
912 if (TAILQ_FIRST(&requests) != NULL) 930 if (TAILQ_FIRST(&requests) != NULL)
913 fatal("Transfer complete, but requests still in queue"); 931 fatal("Transfer complete, but requests still in queue");
@@ -1018,6 +1036,11 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1018 1036
1019 /* Read from local and write to remote */ 1037 /* Read from local and write to remote */
1020 offset = 0; 1038 offset = 0;
1039 if (showprogress)
1040 start_progress_meter(local_path, sb.st_size, &offset);
1041 else
1042 printf("Uploading %s to %s\n", local_path, remote_path);
1043
1021 for (;;) { 1044 for (;;) {
1022 int len; 1045 int len;
1023 1046
@@ -1094,6 +1117,8 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path,
1094 } 1117 }
1095 offset += len; 1118 offset += len;
1096 } 1119 }
1120 if (showprogress)
1121 stop_progress_meter();
1097 xfree(data); 1122 xfree(data);
1098 1123
1099 if (close(local_fd) == -1) { 1124 if (close(local_fd) == -1) {