version 1.186, 2018/09/07 04:26:56 |
version 1.187, 2018/11/16 02:30:20 |
|
|
} |
} |
|
|
static int |
static int |
parse_args(const char **cpp, int *ignore_errors, int *aflag, |
parse_args(const char **cpp, int *ignore_errors, int *disable_echo, int *aflag, |
int *fflag, int *hflag, int *iflag, int *lflag, int *pflag, |
int *fflag, int *hflag, int *iflag, int *lflag, int *pflag, |
int *rflag, int *sflag, |
int *rflag, int *sflag, |
unsigned long *n_arg, char **path1, char **path2) |
unsigned long *n_arg, char **path1, char **path2) |
|
|
/* Skip leading whitespace */ |
/* Skip leading whitespace */ |
cp = cp + strspn(cp, WHITESPACE); |
cp = cp + strspn(cp, WHITESPACE); |
|
|
/* Check for leading '-' (disable error processing) */ |
/* |
|
* Check for leading '-' (disable error processing) and '@' (suppress |
|
* command echo) |
|
*/ |
*ignore_errors = 0; |
*ignore_errors = 0; |
if (*cp == '-') { |
*disable_echo = 0; |
*ignore_errors = 1; |
for (;*cp != '\0'; cp++) { |
cp++; |
if (*cp == '-') { |
cp = cp + strspn(cp, WHITESPACE); |
*ignore_errors = 1; |
|
} else if (*cp == '@') { |
|
*disable_echo = 1; |
|
} else { |
|
/* all other characters terminate prefix processing */ |
|
break; |
|
} |
} |
} |
|
cp = cp + strspn(cp, WHITESPACE); |
|
|
/* Ignore blank lines and lines which begin with comment '#' char */ |
/* Ignore blank lines and lines which begin with comment '#' char */ |
if (*cp == '\0' || *cp == '#') |
if (*cp == '\0' || *cp == '#') |
|
|
|
|
static int |
static int |
parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, |
parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, |
const char *startdir, int err_abort) |
const char *startdir, int err_abort, int echo_command) |
{ |
{ |
|
const char *ocmd = cmd; |
char *path1, *path2, *tmp; |
char *path1, *path2, *tmp; |
int ignore_errors = 0, aflag = 0, fflag = 0, hflag = 0, |
int ignore_errors = 0, disable_echo = 1; |
iflag = 0; |
int aflag = 0, fflag = 0, hflag = 0, iflag = 0; |
int lflag = 0, pflag = 0, rflag = 0, sflag = 0; |
int lflag = 0, pflag = 0, rflag = 0, sflag = 0; |
int cmdnum, i; |
int cmdnum, i; |
unsigned long n_arg = 0; |
unsigned long n_arg = 0; |
|
|
glob_t g; |
glob_t g; |
|
|
path1 = path2 = NULL; |
path1 = path2 = NULL; |
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag, |
cmdnum = parse_args(&cmd, &ignore_errors, &disable_echo, &aflag, &fflag, |
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2); |
&hflag, &iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, |
|
&path1, &path2); |
if (ignore_errors != 0) |
if (ignore_errors != 0) |
err_abort = 0; |
err_abort = 0; |
|
|
|
if (echo_command && !disable_echo) |
|
mprintf("sftp> %s\n", ocmd); |
|
|
memset(&g, 0, sizeof(g)); |
memset(&g, 0, sizeof(g)); |
|
|
/* Perform command */ |
/* Perform command */ |
|
|
mprintf("Changing to: %s\n", dir); |
mprintf("Changing to: %s\n", dir); |
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); |
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); |
if (parse_dispatch_command(conn, cmd, |
if (parse_dispatch_command(conn, cmd, |
&remote_path, startdir, 1) != 0) { |
&remote_path, startdir, 1, 0) != 0) { |
free(dir); |
free(dir); |
free(startdir); |
free(startdir); |
free(remote_path); |
free(remote_path); |
|
|
file2 == NULL ? "" : " ", |
file2 == NULL ? "" : " ", |
file2 == NULL ? "" : file2); |
file2 == NULL ? "" : file2); |
err = parse_dispatch_command(conn, cmd, |
err = parse_dispatch_command(conn, cmd, |
&remote_path, startdir, 1); |
&remote_path, startdir, 1, 0); |
free(dir); |
free(dir); |
free(startdir); |
free(startdir); |
free(remote_path); |
free(remote_path); |
|
|
interactive = !batchmode && isatty(STDIN_FILENO); |
interactive = !batchmode && isatty(STDIN_FILENO); |
err = 0; |
err = 0; |
for (;;) { |
for (;;) { |
char *cp; |
|
const char *line; |
const char *line; |
int count = 0; |
int count = 0; |
|
|
|
|
printf("\n"); |
printf("\n"); |
break; |
break; |
} |
} |
if (!interactive) { /* Echo command */ |
|
mprintf("sftp> %s", cmd); |
|
if (strlen(cmd) > 0 && |
|
cmd[strlen(cmd) - 1] != '\n') |
|
printf("\n"); |
|
} |
|
} else { |
} else { |
if ((line = el_gets(el, &count)) == NULL || |
if ((line = el_gets(el, &count)) == NULL || |
count <= 0) { |
count <= 0) { |
|
|
} |
} |
} |
} |
|
|
cp = strrchr(cmd, '\n'); |
cmd[strcspn(cmd, "\n")] = '\0'; |
if (cp) |
|
*cp = '\0'; |
|
|
|
/* Handle user interrupts gracefully during commands */ |
/* Handle user interrupts gracefully during commands */ |
interrupted = 0; |
interrupted = 0; |
signal(SIGINT, cmd_interrupt); |
signal(SIGINT, cmd_interrupt); |
|
|
err = parse_dispatch_command(conn, cmd, &remote_path, |
err = parse_dispatch_command(conn, cmd, &remote_path, |
startdir, batchmode); |
startdir, batchmode, !interactive && el == NULL); |
if (err != 0) |
if (err != 0) |
break; |
break; |
} |
} |