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) | |
download | openssh-git-44f75c14f6f1eacfe6e1c98eae742019de24ad6a.tar.gz |
- 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 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.38 2003/10/08 08:27:36 jmc Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.39 2004/01/13 09:25:05 djm Exp $"); #include "buffer.h" #include "xmalloc.h" @@ -43,7 +43,8 @@ extern char *__progname; char *__progname; #endif -FILE* infile; +FILE* infile = stdin; +int batchmode = 0; size_t copy_buffer_len = 32768; size_t num_requests = 16; static pid_t sshpid = -1; @@ -141,7 +142,6 @@ main(int argc, char **argv) addargs(&args, "-oForwardAgent no"); addargs(&args, "-oClearAllForwardings yes"); ll = SYSLOG_LEVEL_INFO; - infile = stdin; /* Read from STDIN unless changed by -b */ while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) { switch (ch) { @@ -171,13 +171,15 @@ main(int argc, char **argv) ssh_program = optarg; break; case 'b': - if (infile == stdin) { - infile = fopen(optarg, "r"); - if (infile == NULL) - fatal("%s (%s).", strerror(errno), optarg); - } else - fatal("Filename already specified."); + if (batchmode) + fatal("Batch file already specified."); + + /* Allow "-" as stdin */ + if (strcmp(optarg, "-") != 0 && + (infile = fopen(optarg, "r")) == NULL) + fatal("%s (%s).", strerror(errno), optarg); showprogress = 0; + batchmode = 1; break; case 'P': sftp_direct = optarg; @@ -241,13 +243,15 @@ main(int argc, char **argv) sftp_server : "sftp")); args.list[0] = ssh_program; - fprintf(stderr, "Connecting to %s...\n", host); + if (!batchmode) + fprintf(stderr, "Connecting to %s...\n", host); connect_to_server(ssh_program, args.list, &in, &out); } else { args.list = NULL; addargs(&args, "sftp-server"); - fprintf(stderr, "Attaching to %s...\n", sftp_direct); + if (!batchmode) + fprintf(stderr, "Attaching to %s...\n", sftp_direct); connect_to_server(sftp_direct, args.list, &in, &out); } @@ -260,7 +264,7 @@ main(int argc, char **argv) close(in); close(out); - if (infile != stdin) + if (batchmode) fclose(infile); while (waitpid(sshpid, NULL, 0) == -1) |