diff options
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | 26 | ||
27 | RCSID("$OpenBSD: sftp.c,v 1.9 2001/03/03 23:52:22 markus Exp $"); | 27 | RCSID("$OpenBSD: sftp.c,v 1.10 2001/03/06 06:11:44 deraadt Exp $"); |
28 | 28 | ||
29 | /* XXX: commandline mode */ | 29 | /* XXX: commandline mode */ |
30 | /* XXX: copy between two remote hosts (commandline) */ | 30 | /* XXX: copy between two remote hosts (commandline) */ |
@@ -49,6 +49,7 @@ char *__progname; | |||
49 | int use_ssh1 = 0; | 49 | int use_ssh1 = 0; |
50 | char *ssh_program = _PATH_SSH_PROGRAM; | 50 | char *ssh_program = _PATH_SSH_PROGRAM; |
51 | char *sftp_server = NULL; | 51 | char *sftp_server = NULL; |
52 | FILE* infile; | ||
52 | 53 | ||
53 | void | 54 | void |
54 | connect_to_server(char **args, int *in, int *out, pid_t *sshpid) | 55 | connect_to_server(char **args, int *in, int *out, pid_t *sshpid) |
@@ -146,7 +147,7 @@ make_ssh_args(char *add_arg) | |||
146 | void | 147 | void |
147 | usage(void) | 148 | usage(void) |
148 | { | 149 | { |
149 | fprintf(stderr, "usage: sftp [-1vC] [-osshopt=value] [user@]host\n"); | 150 | fprintf(stderr, "usage: sftp [-1vC] [-b batchfile] [-osshopt=value] [user@]host\n"); |
150 | exit(1); | 151 | exit(1); |
151 | } | 152 | } |
152 | 153 | ||
@@ -161,9 +162,10 @@ main(int argc, char **argv) | |||
161 | extern char *optarg; | 162 | extern char *optarg; |
162 | 163 | ||
163 | __progname = get_progname(argv[0]); | 164 | __progname = get_progname(argv[0]); |
165 | infile = stdin; /* Read from STDIN unless changed by -b */ | ||
164 | debug_level = compress_flag = 0; | 166 | debug_level = compress_flag = 0; |
165 | 167 | ||
166 | while ((ch = getopt(argc, argv, "1hvCo:s:S:")) != -1) { | 168 | while ((ch = getopt(argc, argv, "1hvCo:s:S:b:")) != -1) { |
167 | switch (ch) { | 169 | switch (ch) { |
168 | case 'C': | 170 | case 'C': |
169 | compress_flag = 1; | 171 | compress_flag = 1; |
@@ -186,6 +188,14 @@ main(int argc, char **argv) | |||
186 | case 'S': | 188 | case 'S': |
187 | ssh_program = optarg; | 189 | ssh_program = optarg; |
188 | break; | 190 | break; |
191 | case 'b': | ||
192 | if (infile == stdin) { | ||
193 | infile = fopen(optarg, "r"); | ||
194 | if (infile == NULL) | ||
195 | fatal("%s (%s).", strerror(errno), optarg); | ||
196 | } else | ||
197 | fatal("Filename already specified."); | ||
198 | break; | ||
189 | case 'h': | 199 | case 'h': |
190 | default: | 200 | default: |
191 | usage(); | 201 | usage(); |
@@ -257,6 +267,8 @@ main(int argc, char **argv) | |||
257 | 267 | ||
258 | close(in); | 268 | close(in); |
259 | close(out); | 269 | close(out); |
270 | if (infile != stdin) | ||
271 | fclose(infile); | ||
260 | 272 | ||
261 | if (waitpid(sshpid, NULL, 0) == -1) | 273 | if (waitpid(sshpid, NULL, 0) == -1) |
262 | fatal("Couldn't wait for ssh process: %s", strerror(errno)); | 274 | fatal("Couldn't wait for ssh process: %s", strerror(errno)); |