#include "includes.h"
-RCSID("$OpenBSD: sftp.c,v 1.36 2003/06/04 12:41:22 djm Exp $");
+RCSID("$OpenBSD: sftp.c,v 1.41 2004/01/27 10:08:10 djm Exp $");
#include "buffer.h"
#include "xmalloc.h"
#endif
FILE* infile;
+int batchmode = 0;
size_t copy_buffer_len = 32768;
size_t num_requests = 16;
static pid_t sshpid = -1;
extern char *__progname;
fprintf(stderr,
- "usage: %s [-vC1] [-b batchfile] [-o option] [-s subsystem|path] [-B buffer_size]\n"
- " [-F config] [-P direct server path] [-S program]\n"
- " [user@]host[:file [file]]\n", __progname);
+ "usage: %s [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]\n"
+ " [-o ssh_option] [-P sftp_server_path] [-R num_requests]\n"
+ " [-S program] [-s subsystem | sftp_server] host\n"
+ " %s [[user@]host[:file [file]]]\n"
+ " %s [[user@]host[:dir[/]]]\n"
+ " %s -b batchfile [user@]host\n", __progname, __progname, __progname, __progname);
exit(1);
}
extern int optind;
extern char *optarg;
- __progname = get_progname(argv[0]);
+ __progname = ssh_get_progname(argv[0]);
args.list = NULL;
addargs(&args, "ssh"); /* overwritten with ssh_program */
addargs(&args, "-oForwardX11 no");
addargs(&args, "-oForwardAgent no");
addargs(&args, "-oClearAllForwardings yes");
+
ll = SYSLOG_LEVEL_INFO;
- infile = stdin; /* Read from STDIN unless changed by -b */
+ infile = stdin;
while ((ch = getopt(argc, argv, "1hvCo:s:S:b:B:F:P:R:")) != -1) {
switch (ch) {
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;
userhost = xstrdup(argv[optind]);
file2 = argv[optind+1];
- if ((cp = colon(userhost)) != NULL) {
- *cp++ = '\0';
- file1 = cp;
- }
-
if ((host = strrchr(userhost, '@')) == NULL)
host = userhost;
else {
addargs(&args, "-l%s",userhost);
}
+ if ((cp = colon(host)) != NULL) {
+ *cp++ = '\0';
+ file1 = cp;
+ }
+
host = cleanhostname(host);
if (!*host) {
fprintf(stderr, "Missing hostname\n");
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);
}
close(in);
close(out);
- if (infile != stdin)
+ if (batchmode)
fclose(infile);
while (waitpid(sshpid, NULL, 0) == -1)