diff options
author | Damien Miller <djm@mindrot.org> | 2003-01-10 21:43:24 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2003-01-10 21:43:24 +1100 |
commit | 62d57f605a84b8d80803a36a612a37a5137a9963 (patch) | |
tree | d8299282efb2b5216109b302d9e369b67c3e69cd | |
parent | 956f3fb28b93420e87a51d1611029accebb2e43b (diff) |
- fgsch@cvs.openbsd.org 2003/01/10 08:19:07
[scp.c sftp.1 sftp.c sftp-client.c sftp-int.c]
sftp progress meter support.
original diffs by Nils Nordman <nino at nforced dot com> via
markus@, merged to -current by me, djm@ ok.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | Makefile.in | 10 | ||||
-rw-r--r-- | scp.c | 211 | ||||
-rw-r--r-- | sftp-client.c | 27 | ||||
-rw-r--r-- | sftp-int.c | 18 | ||||
-rw-r--r-- | sftp.1 | 4 | ||||
-rw-r--r-- | sftp.c | 5 |
7 files changed, 69 insertions, 213 deletions
@@ -8,6 +8,11 @@ | |||
8 | Allow blank lines and comments in input | 8 | Allow blank lines and comments in input |
9 | Ability to suppress abort on error in batchmode ("-put blah") | 9 | Ability to suppress abort on error in batchmode ("-put blah") |
10 | Fixes mindrot bug #452; markus@ ok | 10 | Fixes mindrot bug #452; markus@ ok |
11 | - fgsch@cvs.openbsd.org 2003/01/10 08:19:07 | ||
12 | [scp.c sftp.1 sftp.c sftp-client.c sftp-int.c] | ||
13 | sftp progress meter support. | ||
14 | original diffs by Nils Nordman <nino at nforced dot com> via | ||
15 | markus@, merged to -current by me, djm@ ok. | ||
11 | 16 | ||
12 | 20030108 | 17 | 20030108 |
13 | - (djm) Sync openbsd-compat/ with OpenBSD -current | 18 | - (djm) Sync openbsd-compat/ with OpenBSD -current |
@@ -976,4 +981,4 @@ | |||
976 | save auth method before monitor_reset_key_state(); bugzilla bug #284; | 981 | save auth method before monitor_reset_key_state(); bugzilla bug #284; |
977 | ok provos@ | 982 | ok provos@ |
978 | 983 | ||
979 | $Id: ChangeLog,v 1.2559 2003/01/10 10:40:00 djm Exp $ | 984 | $Id: ChangeLog,v 1.2560 2003/01/10 10:43:24 djm Exp $ |
diff --git a/Makefile.in b/Makefile.in index 85b108d16..8d5987afd 100644 --- a/Makefile.in +++ b/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.223 2003/01/09 01:22:59 tim Exp $ | 1 | # $Id: Makefile.in,v 1.224 2003/01/10 10:43:25 djm Exp $ |
2 | 2 | ||
3 | # uncomment if you run a non bourne compatable shell. Ie. csh | 3 | # uncomment if you run a non bourne compatable shell. Ie. csh |
4 | #SHELL = @SH@ | 4 | #SHELL = @SH@ |
@@ -117,8 +117,8 @@ ssh$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHOBJS) | |||
117 | sshd$(EXEEXT): libssh.a $(LIBCOMPAT) $(SSHDOBJS) | 117 | sshd$(EXEEXT): libssh.a $(LIBCOMPAT) $(SSHDOBJS) |
118 | $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBWRAP) $(LIBPAM) $(LIBS) | 118 | $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBWRAP) $(LIBPAM) $(LIBS) |
119 | 119 | ||
120 | scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o | 120 | scp$(EXEEXT): $(LIBCOMPAT) libssh.a scp.o progressmeter.o |
121 | $(LD) -o $@ scp.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 121 | $(LD) -o $@ scp.o progressmeter.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
122 | 122 | ||
123 | ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o | 123 | ssh-add$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-add.o |
124 | $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 124 | $(LD) -o $@ ssh-add.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
@@ -138,8 +138,8 @@ ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o | |||
138 | sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o | 138 | sftp-server$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-common.o sftp-server.o |
139 | $(LD) -o $@ sftp-server.o sftp-common.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 139 | $(LD) -o $@ sftp-server.o sftp-common.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
140 | 140 | ||
141 | sftp$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-client.o sftp-int.o sftp-common.o sftp-glob.o | 141 | sftp$(EXEEXT): $(LIBCOMPAT) libssh.a sftp.o sftp-client.o sftp-int.o sftp-common.o sftp-glob.o progressmeter.o |
142 | $(LD) -o $@ sftp.o sftp-client.o sftp-common.o sftp-int.o sftp-glob.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 142 | $(LD) -o $@ progressmeter.o sftp.o sftp-client.o sftp-common.o sftp-int.o sftp-glob.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
143 | 143 | ||
144 | ssh-rand-helper${EXEEXT}: $(LIBCOMPAT) libssh.a ssh-rand-helper.o | 144 | ssh-rand-helper${EXEEXT}: $(LIBCOMPAT) libssh.a ssh-rand-helper.o |
145 | $(LD) -o $@ ssh-rand-helper.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) | 145 | $(LD) -o $@ ssh-rand-helper.o $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) |
@@ -75,13 +75,14 @@ | |||
75 | */ | 75 | */ |
76 | 76 | ||
77 | #include "includes.h" | 77 | #include "includes.h" |
78 | RCSID("$OpenBSD: scp.c,v 1.96 2002/12/13 15:20:52 markus Exp $"); | 78 | RCSID("$OpenBSD: scp.c,v 1.97 2003/01/10 08:19:07 fgsch Exp $"); |
79 | 79 | ||
80 | #include "xmalloc.h" | 80 | #include "xmalloc.h" |
81 | #include "atomicio.h" | 81 | #include "atomicio.h" |
82 | #include "pathnames.h" | 82 | #include "pathnames.h" |
83 | #include "log.h" | 83 | #include "log.h" |
84 | #include "misc.h" | 84 | #include "misc.h" |
85 | #include "progressmeter.h" | ||
85 | 86 | ||
86 | #ifdef HAVE___PROGNAME | 87 | #ifdef HAVE___PROGNAME |
87 | extern char *__progname; | 88 | extern char *__progname; |
@@ -89,30 +90,9 @@ extern char *__progname; | |||
89 | char *__progname; | 90 | char *__progname; |
90 | #endif | 91 | #endif |
91 | 92 | ||
92 | /* For progressmeter() -- number of seconds before xfer considered "stalled" */ | ||
93 | #define STALLTIME 5 | ||
94 | /* alarm() interval for updating progress meter */ | ||
95 | #define PROGRESSTIME 1 | ||
96 | |||
97 | /* Visual statistics about files as they are transferred. */ | ||
98 | void progressmeter(int); | ||
99 | |||
100 | /* Returns width of the terminal (for progress meter calculations). */ | ||
101 | int getttywidth(void); | ||
102 | int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc); | ||
103 | |||
104 | /* Struct for addargs */ | 93 | /* Struct for addargs */ |
105 | arglist args; | 94 | arglist args; |
106 | 95 | ||
107 | /* Time a transfer started. */ | ||
108 | static struct timeval start; | ||
109 | |||
110 | /* Number of bytes of current file transferred so far. */ | ||
111 | volatile off_t statbytes; | ||
112 | |||
113 | /* Total size of current file. */ | ||
114 | off_t totalbytes = 0; | ||
115 | |||
116 | /* Name of current file being transferred. */ | 96 | /* Name of current file being transferred. */ |
117 | char *curfile; | 97 | char *curfile; |
118 | 98 | ||
@@ -505,7 +485,7 @@ source(argc, argv) | |||
505 | struct stat stb; | 485 | struct stat stb; |
506 | static BUF buffer; | 486 | static BUF buffer; |
507 | BUF *bp; | 487 | BUF *bp; |
508 | off_t i, amt, result; | 488 | off_t i, amt, result, statbytes; |
509 | int fd, haderr, indx; | 489 | int fd, haderr, indx; |
510 | char *last, *name, buf[2048]; | 490 | char *last, *name, buf[2048]; |
511 | int len; | 491 | int len; |
@@ -578,10 +558,8 @@ syserr: run_err("%s: %s", name, strerror(errno)); | |||
578 | next: (void) close(fd); | 558 | next: (void) close(fd); |
579 | continue; | 559 | continue; |
580 | } | 560 | } |
581 | if (showprogress) { | 561 | if (showprogress) |
582 | totalbytes = stb.st_size; | 562 | start_progress_meter(curfile, stb.st_size, &statbytes); |
583 | progressmeter(-1); | ||
584 | } | ||
585 | /* Keep writing after an error so that we stay sync'd up. */ | 563 | /* Keep writing after an error so that we stay sync'd up. */ |
586 | for (haderr = i = 0; i < stb.st_size; i += bp->cnt) { | 564 | for (haderr = i = 0; i < stb.st_size; i += bp->cnt) { |
587 | amt = bp->cnt; | 565 | amt = bp->cnt; |
@@ -602,7 +580,7 @@ next: (void) close(fd); | |||
602 | } | 580 | } |
603 | } | 581 | } |
604 | if (showprogress) | 582 | if (showprogress) |
605 | progressmeter(1); | 583 | stop_progress_meter(); |
606 | 584 | ||
607 | if (close(fd) < 0 && !haderr) | 585 | if (close(fd) < 0 && !haderr) |
608 | haderr = errno; | 586 | haderr = errno; |
@@ -682,7 +660,7 @@ sink(argc, argv) | |||
682 | BUF *bp; | 660 | BUF *bp; |
683 | off_t i, j; | 661 | off_t i, j; |
684 | int amt, count, exists, first, mask, mode, ofd, omode; | 662 | int amt, count, exists, first, mask, mode, ofd, omode; |
685 | off_t size; | 663 | off_t size, statbytes; |
686 | int setimes, targisdir, wrerrno = 0; | 664 | int setimes, targisdir, wrerrno = 0; |
687 | char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; | 665 | char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; |
688 | struct timeval tv[2]; | 666 | struct timeval tv[2]; |
@@ -844,11 +822,9 @@ bad: run_err("%s: %s", np, strerror(errno)); | |||
844 | cp = bp->buf; | 822 | cp = bp->buf; |
845 | wrerr = NO; | 823 | wrerr = NO; |
846 | 824 | ||
847 | if (showprogress) { | ||
848 | totalbytes = size; | ||
849 | progressmeter(-1); | ||
850 | } | ||
851 | statbytes = 0; | 825 | statbytes = 0; |
826 | if (showprogress) | ||
827 | start_progress_meter(curfile, size, &statbytes); | ||
852 | for (count = i = 0; i < size; i += 4096) { | 828 | for (count = i = 0; i < size; i += 4096) { |
853 | amt = 4096; | 829 | amt = 4096; |
854 | if (i + amt > size) | 830 | if (i + amt > size) |
@@ -882,7 +858,7 @@ bad: run_err("%s: %s", np, strerror(errno)); | |||
882 | } | 858 | } |
883 | } | 859 | } |
884 | if (showprogress) | 860 | if (showprogress) |
885 | progressmeter(1); | 861 | stop_progress_meter(); |
886 | if (count != 0 && wrerr == NO && | 862 | if (count != 0 && wrerr == NO && |
887 | (j = atomicio(write, ofd, bp->buf, count)) != count) { | 863 | (j = atomicio(write, ofd, bp->buf, count)) != count) { |
888 | wrerr = YES; | 864 | wrerr = YES; |
@@ -1086,170 +1062,3 @@ lostconn(signo) | |||
1086 | else | 1062 | else |
1087 | exit(1); | 1063 | exit(1); |
1088 | } | 1064 | } |
1089 | |||
1090 | static void | ||
1091 | updateprogressmeter(int ignore) | ||
1092 | { | ||
1093 | int save_errno = errno; | ||
1094 | |||
1095 | progressmeter(0); | ||
1096 | signal(SIGALRM, updateprogressmeter); | ||
1097 | alarm(PROGRESSTIME); | ||
1098 | errno = save_errno; | ||
1099 | } | ||
1100 | |||
1101 | static int | ||
1102 | foregroundproc(void) | ||
1103 | { | ||
1104 | static pid_t pgrp = -1; | ||
1105 | int ctty_pgrp; | ||
1106 | |||
1107 | if (pgrp == -1) | ||
1108 | pgrp = getpgrp(); | ||
1109 | |||
1110 | #ifdef HAVE_TCGETPGRP | ||
1111 | return ((ctty_pgrp = tcgetpgrp(STDOUT_FILENO)) != -1 && | ||
1112 | ctty_pgrp == pgrp); | ||
1113 | #else | ||
1114 | return ((ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) != -1 && | ||
1115 | ctty_pgrp == pgrp)); | ||
1116 | #endif | ||
1117 | } | ||
1118 | |||
1119 | void | ||
1120 | progressmeter(int flag) | ||
1121 | { | ||
1122 | static const char spaces[] = " " | ||
1123 | " " | ||
1124 | " " | ||
1125 | " " | ||
1126 | " " | ||
1127 | " "; | ||
1128 | static const char prefixes[] = " KMGTP"; | ||
1129 | static struct timeval lastupdate; | ||
1130 | static off_t lastsize; | ||
1131 | struct timeval now, td, wait; | ||
1132 | off_t cursize, abbrevsize, bytespersec; | ||
1133 | double elapsed; | ||
1134 | int ratio, remaining, i, ai, bi, nspaces; | ||
1135 | char buf[512]; | ||
1136 | |||
1137 | if (flag == -1) { | ||
1138 | (void) gettimeofday(&start, (struct timezone *) 0); | ||
1139 | lastupdate = start; | ||
1140 | lastsize = 0; | ||
1141 | } | ||
1142 | if (foregroundproc() == 0) | ||
1143 | return; | ||
1144 | |||
1145 | (void) gettimeofday(&now, (struct timezone *) 0); | ||
1146 | cursize = statbytes; | ||
1147 | if (totalbytes != 0) { | ||
1148 | ratio = 100.0 * cursize / totalbytes; | ||
1149 | ratio = MAX(ratio, 0); | ||
1150 | ratio = MIN(ratio, 100); | ||
1151 | } else | ||
1152 | ratio = 100; | ||
1153 | |||
1154 | abbrevsize = cursize; | ||
1155 | for (ai = 0; abbrevsize >= 10000 && ai < sizeof(prefixes); ai++) | ||
1156 | abbrevsize >>= 10; | ||
1157 | |||
1158 | timersub(&now, &lastupdate, &wait); | ||
1159 | if (cursize > lastsize) { | ||
1160 | lastupdate = now; | ||
1161 | lastsize = cursize; | ||
1162 | wait.tv_sec = 0; | ||
1163 | } | ||
1164 | timersub(&now, &start, &td); | ||
1165 | elapsed = td.tv_sec + (td.tv_usec / 1000000.0); | ||
1166 | |||
1167 | bytespersec = 0; | ||
1168 | if (statbytes > 0) { | ||
1169 | bytespersec = statbytes; | ||
1170 | if (elapsed > 0.0) | ||
1171 | bytespersec /= elapsed; | ||
1172 | } | ||
1173 | for (bi = 1; bytespersec >= 1024000 && bi < sizeof(prefixes); bi++) | ||
1174 | bytespersec >>= 10; | ||
1175 | |||
1176 | nspaces = MIN(getttywidth() - 79, sizeof(spaces) - 1); | ||
1177 | |||
1178 | #ifdef HAVE_LONG_LONG_INT | ||
1179 | snprintf(buf, sizeof(buf), | ||
1180 | "\r%-45.45s%.*s%3d%% %4lld%c%c %3lld.%01d%cB/s", | ||
1181 | curfile, | ||
1182 | nspaces, | ||
1183 | spaces, | ||
1184 | ratio, | ||
1185 | (long long)abbrevsize, | ||
1186 | prefixes[ai], | ||
1187 | ai == 0 ? ' ' : 'B', | ||
1188 | (long long)(bytespersec / 1024), | ||
1189 | (int)((bytespersec % 1024) * 10 / 1024), | ||
1190 | prefixes[bi] | ||
1191 | ); | ||
1192 | #else | ||
1193 | snprintf(buf, sizeof(buf), | ||
1194 | "\r%-45.45s%.*s%3d%% %4lld%c%c %3lu.%01d%cB/s", | ||
1195 | curfile, | ||
1196 | nspaces, | ||
1197 | spaces, | ||
1198 | ratio, | ||
1199 | (u_long)abbrevsize, | ||
1200 | prefixes[ai], | ||
1201 | ai == 0 ? ' ' : 'B', | ||
1202 | (u_long)(bytespersec / 1024), | ||
1203 | (int)((bytespersec % 1024) * 10 / 1024), | ||
1204 | prefixes[bi] | ||
1205 | ); | ||
1206 | #endif | ||
1207 | |||
1208 | if (flag != 1 && | ||
1209 | (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) { | ||
1210 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
1211 | " --:-- ETA"); | ||
1212 | } else if (wait.tv_sec >= STALLTIME) { | ||
1213 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
1214 | " - stalled -"); | ||
1215 | } else { | ||
1216 | if (flag != 1) | ||
1217 | remaining = (int)(totalbytes / (statbytes / elapsed) - | ||
1218 | elapsed); | ||
1219 | else | ||
1220 | remaining = elapsed; | ||
1221 | |||
1222 | i = remaining / 3600; | ||
1223 | if (i) | ||
1224 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
1225 | "%2d:", i); | ||
1226 | else | ||
1227 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
1228 | " "); | ||
1229 | i = remaining % 3600; | ||
1230 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
1231 | "%02d:%02d%s", i / 60, i % 60, | ||
1232 | (flag != 1) ? " ETA" : " "); | ||
1233 | } | ||
1234 | atomicio(write, fileno(stdout), buf, strlen(buf)); | ||
1235 | |||
1236 | if (flag == -1) { | ||
1237 | mysignal(SIGALRM, updateprogressmeter); | ||
1238 | alarm(PROGRESSTIME); | ||
1239 | } else if (flag == 1) { | ||
1240 | alarm(0); | ||
1241 | atomicio(write, fileno(stdout), "\n", 1); | ||
1242 | statbytes = 0; | ||
1243 | } | ||
1244 | } | ||
1245 | |||
1246 | int | ||
1247 | getttywidth(void) | ||
1248 | { | ||
1249 | struct winsize winsize; | ||
1250 | |||
1251 | if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1) | ||
1252 | return (winsize.ws_col ? winsize.ws_col : 80); | ||
1253 | else | ||
1254 | return (80); | ||
1255 | } | ||
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" |
31 | RCSID("$OpenBSD: sftp-client.c,v 1.38 2003/01/06 23:51:22 djm Exp $"); | 31 | RCSID("$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 | ||
47 | extern 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) { |
diff --git a/sftp-int.c b/sftp-int.c index f2c8fa6dc..88b0530ab 100644 --- a/sftp-int.c +++ b/sftp-int.c | |||
@@ -25,7 +25,7 @@ | |||
25 | /* XXX: recursive operations */ | 25 | /* XXX: recursive operations */ |
26 | 26 | ||
27 | #include "includes.h" | 27 | #include "includes.h" |
28 | RCSID("$OpenBSD: sftp-int.c,v 1.51 2003/01/08 23:53:26 djm Exp $"); | 28 | RCSID("$OpenBSD: sftp-int.c,v 1.52 2003/01/10 08:19:07 fgsch Exp $"); |
29 | 29 | ||
30 | #include "buffer.h" | 30 | #include "buffer.h" |
31 | #include "xmalloc.h" | 31 | #include "xmalloc.h" |
@@ -47,6 +47,9 @@ extern size_t copy_buffer_len; | |||
47 | /* Number of concurrent outstanding requests */ | 47 | /* Number of concurrent outstanding requests */ |
48 | extern int num_requests; | 48 | extern int num_requests; |
49 | 49 | ||
50 | /* This is set to 0 if the progressmeter is not desired. */ | ||
51 | int showprogress = 1; | ||
52 | |||
50 | /* Seperators for interactive commands */ | 53 | /* Seperators for interactive commands */ |
51 | #define WHITESPACE " \t\r\n" | 54 | #define WHITESPACE " \t\r\n" |
52 | 55 | ||
@@ -73,6 +76,7 @@ extern int num_requests; | |||
73 | #define I_SHELL 20 | 76 | #define I_SHELL 20 |
74 | #define I_SYMLINK 21 | 77 | #define I_SYMLINK 21 |
75 | #define I_VERSION 22 | 78 | #define I_VERSION 22 |
79 | #define I_PROGRESS 23 | ||
76 | 80 | ||
77 | struct CMD { | 81 | struct CMD { |
78 | const char *c; | 82 | const char *c; |
@@ -100,6 +104,7 @@ const struct CMD cmds[] = { | |||
100 | { "ls", I_LS }, | 104 | { "ls", I_LS }, |
101 | { "lumask", I_LUMASK }, | 105 | { "lumask", I_LUMASK }, |
102 | { "mkdir", I_MKDIR }, | 106 | { "mkdir", I_MKDIR }, |
107 | { "progress", I_PROGRESS }, | ||
103 | { "put", I_PUT }, | 108 | { "put", I_PUT }, |
104 | { "mput", I_PUT }, | 109 | { "mput", I_PUT }, |
105 | { "pwd", I_PWD }, | 110 | { "pwd", I_PWD }, |
@@ -132,6 +137,7 @@ help(void) | |||
132 | printf("ls [path] Display remote directory listing\n"); | 137 | printf("ls [path] Display remote directory listing\n"); |
133 | printf("lumask umask Set local umask to 'umask'\n"); | 138 | printf("lumask umask Set local umask to 'umask'\n"); |
134 | printf("mkdir path Create remote directory\n"); | 139 | printf("mkdir path Create remote directory\n"); |
140 | printf("preogress Toggle display of progress meter\n"); | ||
135 | printf("put local-path [remote-path] Upload file\n"); | 141 | printf("put local-path [remote-path] Upload file\n"); |
136 | printf("pwd Display remote working directory\n"); | 142 | printf("pwd Display remote working directory\n"); |
137 | printf("exit Quit sftp\n"); | 143 | printf("exit Quit sftp\n"); |
@@ -425,7 +431,6 @@ process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) | |||
425 | err = -1; | 431 | err = -1; |
426 | goto out; | 432 | goto out; |
427 | } | 433 | } |
428 | printf("Fetching %s to %s\n", g.gl_pathv[0], abs_dst); | ||
429 | err = do_download(conn, g.gl_pathv[0], abs_dst, pflag); | 434 | err = do_download(conn, g.gl_pathv[0], abs_dst, pflag); |
430 | goto out; | 435 | goto out; |
431 | } | 436 | } |
@@ -507,7 +512,6 @@ process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, int pflag) | |||
507 | } | 512 | } |
508 | abs_dst = make_absolute(abs_dst, pwd); | 513 | abs_dst = make_absolute(abs_dst, pwd); |
509 | } | 514 | } |
510 | printf("Uploading %s to %s\n", g.gl_pathv[0], abs_dst); | ||
511 | err = do_upload(conn, g.gl_pathv[0], abs_dst, pflag); | 515 | err = do_upload(conn, g.gl_pathv[0], abs_dst, pflag); |
512 | goto out; | 516 | goto out; |
513 | } | 517 | } |
@@ -810,6 +814,7 @@ parse_args(const char **cpp, int *pflag, int *lflag, int *iflag, | |||
810 | case I_LPWD: | 814 | case I_LPWD: |
811 | case I_HELP: | 815 | case I_HELP: |
812 | case I_VERSION: | 816 | case I_VERSION: |
817 | case I_PROGRESS: | ||
813 | break; | 818 | break; |
814 | default: | 819 | default: |
815 | fatal("Command not implemented"); | 820 | fatal("Command not implemented"); |
@@ -1015,6 +1020,13 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, | |||
1015 | case I_VERSION: | 1020 | case I_VERSION: |
1016 | printf("SFTP protocol version %u\n", sftp_proto_version(conn)); | 1021 | printf("SFTP protocol version %u\n", sftp_proto_version(conn)); |
1017 | break; | 1022 | break; |
1023 | case I_PROGRESS: | ||
1024 | showprogress = !showprogress; | ||
1025 | if (showprogress) | ||
1026 | printf("Progress meter enabled\n"); | ||
1027 | else | ||
1028 | printf("Progress meter disabled\n"); | ||
1029 | break; | ||
1018 | default: | 1030 | default: |
1019 | fatal("%d is not implemented", cmdnum); | 1031 | fatal("%d is not implemented", cmdnum); |
1020 | } | 1032 | } |
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: sftp.1,v 1.39 2003/01/08 23:53:26 djm Exp $ | 1 | .\" $OpenBSD: sftp.1,v 1.40 2003/01/10 08:19:07 fgsch Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2001 Damien Miller. All rights reserved. | 3 | .\" Copyright (c) 2001 Damien Miller. All rights reserved. |
4 | .\" | 4 | .\" |
@@ -228,6 +228,8 @@ Set local umask to | |||
228 | .It Ic mkdir Ar path | 228 | .It Ic mkdir Ar path |
229 | Create remote directory specified by | 229 | Create remote directory specified by |
230 | .Ar path . | 230 | .Ar path . |
231 | .It Ic progress | ||
232 | Toggle display of progress meter. | ||
231 | .It Xo Ic put | 233 | .It Xo Ic put |
232 | .Op Ar flags | 234 | .Op Ar flags |
233 | .Ar local-path | 235 | .Ar local-path |
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | RCSID("$OpenBSD: sftp.c,v 1.33 2003/01/08 23:53:26 djm Exp $"); | 27 | RCSID("$OpenBSD: sftp.c,v 1.34 2003/01/10 08:19:07 fgsch Exp $"); |
28 | 28 | ||
29 | /* XXX: short-form remote directory listings (like 'ls -C') */ | 29 | /* XXX: short-form remote directory listings (like 'ls -C') */ |
30 | 30 | ||
@@ -49,6 +49,8 @@ FILE* infile; | |||
49 | size_t copy_buffer_len = 32768; | 49 | size_t copy_buffer_len = 32768; |
50 | size_t num_requests = 16; | 50 | size_t num_requests = 16; |
51 | 51 | ||
52 | extern int showprogress; | ||
53 | |||
52 | static void | 54 | static void |
53 | connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) | 55 | connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) |
54 | { | 56 | { |
@@ -162,6 +164,7 @@ main(int argc, char **argv) | |||
162 | fatal("%s (%s).", strerror(errno), optarg); | 164 | fatal("%s (%s).", strerror(errno), optarg); |
163 | } else | 165 | } else |
164 | fatal("Filename already specified."); | 166 | fatal("Filename already specified."); |
167 | showprogress = 0; | ||
165 | break; | 168 | break; |
166 | case 'P': | 169 | case 'P': |
167 | sftp_direct = optarg; | 170 | sftp_direct = optarg; |