diff options
author | Damien Miller <djm@mindrot.org> | 2004-01-21 10:58:47 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2004-01-21 10:58:47 +1100 |
commit | 44f75c14f6f1eacfe6e1c98eae742019de24ad6a (patch) | |
tree | c0e6e41441881c57b9bdd66bb43fab41d0814a37 /sftp.c | |
parent | a8df9248cea285d1a6d6d1ec8d33a24f208fdc42 (diff) |
- djm@cvs.openbsd.org 2004/01/13 09:25:05
[sftp-int.c sftp.1 sftp.c]
Tidy sftp batchmode handling, eliminate junk to stderr (bugzilla #754) and
enable use of "-b -" to accept batchfile from stdin; ok markus@
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | RCSID("$OpenBSD: sftp.c,v 1.38 2003/10/08 08:27:36 jmc Exp $"); | 27 | RCSID("$OpenBSD: sftp.c,v 1.39 2004/01/13 09:25:05 djm Exp $"); |
28 | 28 | ||
29 | #include "buffer.h" | 29 | #include "buffer.h" |
30 | #include "xmalloc.h" | 30 | #include "xmalloc.h" |
@@ -43,7 +43,8 @@ extern char *__progname; | |||
43 | char *__progname; | 43 | char *__progname; |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | FILE* infile; | 46 | FILE* infile = stdin; |
47 | int batchmode = 0; | ||
47 | size_t copy_buffer_len = 32768; | 48 | size_t copy_buffer_len = 32768; |
48 | size_t num_requests = 16; | 49 | size_t num_requests = 16; |
49 | static pid_t sshpid = -1; | 50 | static pid_t sshpid = -1; |
@@ -141,7 +142,6 @@ main(int argc, char **argv) | |||
141 | addargs(&args, "-oForwardAgent no"); | 142 | addargs(&args, "-oForwardAgent no"); |
142 | addargs(&args, "-oClearAllForwardings yes"); | 143 | addargs(&args, "-oClearAllForwardings yes"); |
143 | ll = SYSLOG_LEVEL_INFO; | 144 | ll = SYSLOG_LEVEL_INFO; |
144 | infile = stdin; /* Read from STDIN unless changed by -b */ | ||
145 | 145 | ||
146 | while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) { | 146 | while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) { |
147 | switch (ch) { | 147 | switch (ch) { |
@@ -171,13 +171,15 @@ main(int argc, char **argv) | |||
171 | ssh_program = optarg; | 171 | ssh_program = optarg; |
172 | break; | 172 | break; |
173 | case 'b': | 173 | case 'b': |
174 | if (infile == stdin) { | 174 | if (batchmode) |
175 | infile = fopen(optarg, "r"); | 175 | fatal("Batch file already specified."); |
176 | if (infile == NULL) | 176 | |
177 | fatal("%s (%s).", strerror(errno), optarg); | 177 | /* Allow "-" as stdin */ |
178 | } else | 178 | if (strcmp(optarg, "-") != 0 && |
179 | fatal("Filename already specified."); | 179 | (infile = fopen(optarg, "r")) == NULL) |
180 | fatal("%s (%s).", strerror(errno), optarg); | ||
180 | showprogress = 0; | 181 | showprogress = 0; |
182 | batchmode = 1; | ||
181 | break; | 183 | break; |
182 | case 'P': | 184 | case 'P': |
183 | sftp_direct = optarg; | 185 | sftp_direct = optarg; |
@@ -241,13 +243,15 @@ main(int argc, char **argv) | |||
241 | sftp_server : "sftp")); | 243 | sftp_server : "sftp")); |
242 | args.list[0] = ssh_program; | 244 | args.list[0] = ssh_program; |
243 | 245 | ||
244 | fprintf(stderr, "Connecting to %s...\n", host); | 246 | if (!batchmode) |
247 | fprintf(stderr, "Connecting to %s...\n", host); | ||
245 | connect_to_server(ssh_program, args.list, &in, &out); | 248 | connect_to_server(ssh_program, args.list, &in, &out); |
246 | } else { | 249 | } else { |
247 | args.list = NULL; | 250 | args.list = NULL; |
248 | addargs(&args, "sftp-server"); | 251 | addargs(&args, "sftp-server"); |
249 | 252 | ||
250 | fprintf(stderr, "Attaching to %s...\n", sftp_direct); | 253 | if (!batchmode) |
254 | fprintf(stderr, "Attaching to %s...\n", sftp_direct); | ||
251 | connect_to_server(sftp_direct, args.list, &in, &out); | 255 | connect_to_server(sftp_direct, args.list, &in, &out); |
252 | } | 256 | } |
253 | 257 | ||
@@ -260,7 +264,7 @@ main(int argc, char **argv) | |||
260 | 264 | ||
261 | close(in); | 265 | close(in); |
262 | close(out); | 266 | close(out); |
263 | if (infile != stdin) | 267 | if (batchmode) |
264 | fclose(infile); | 268 | fclose(infile); |
265 | 269 | ||
266 | while (waitpid(sshpid, NULL, 0) == -1) | 270 | while (waitpid(sshpid, NULL, 0) == -1) |