version 1.63, 2005/03/10 22:01:05 |
version 1.63.2.2, 2006/02/03 02:53:45 |
|
|
{ |
{ |
const char *cp = *cpp, *end; |
const char *cp = *cpp, *end; |
char quot; |
char quot; |
int i, j; |
u_int i, j; |
|
|
cp += strspn(cp, WHITESPACE); |
cp += strspn(cp, WHITESPACE); |
if (!*cp) { |
if (!*cp) { |
|
|
static int |
static int |
do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) |
do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag) |
{ |
{ |
int n, c = 1, colspace = 0, columns = 1; |
int n; |
|
u_int c = 1, colspace = 0, columns = 1; |
SFTP_DIRENT **d; |
SFTP_DIRENT **d; |
|
|
if ((n = do_readdir(conn, path, &d)) != 0) |
if ((n = do_readdir(conn, path, &d)) != 0) |
return (n); |
return (n); |
|
|
if (!(lflag & LS_SHORT_VIEW)) { |
if (!(lflag & LS_SHORT_VIEW)) { |
int m = 0, width = 80; |
u_int m = 0, width = 80; |
struct winsize ws; |
struct winsize ws; |
char *tmp; |
char *tmp; |
|
|
|
|
} |
} |
|
|
if (lflag & SORT_FLAGS) { |
if (lflag & SORT_FLAGS) { |
|
for (n = 0; d[n] != NULL; n++) |
|
; /* count entries */ |
sort_flag = lflag & (SORT_FLAGS|LS_REVERSE_SORT); |
sort_flag = lflag & (SORT_FLAGS|LS_REVERSE_SORT); |
qsort(d, n, sizeof(*d), sdirent_comp); |
qsort(d, n, sizeof(*d), sdirent_comp); |
} |
} |
|
|
int lflag) |
int lflag) |
{ |
{ |
glob_t g; |
glob_t g; |
int i, c = 1, colspace = 0, columns = 1; |
u_int i, c = 1, colspace = 0, columns = 1; |
Attrib *a = NULL; |
Attrib *a = NULL; |
|
|
memset(&g, 0, sizeof(g)); |
memset(&g, 0, sizeof(g)); |
|
|
} |
} |
|
|
if (!(lflag & LS_SHORT_VIEW)) { |
if (!(lflag & LS_SHORT_VIEW)) { |
int m = 0, width = 80; |
u_int m = 0, width = 80; |
struct winsize ws; |
struct winsize ws; |
|
|
/* Count entries for sort and find longest filename */ |
/* Count entries for sort and find longest filename */ |
|
|
char *dir = NULL; |
char *dir = NULL; |
char cmd[2048]; |
char cmd[2048]; |
struct sftp_conn *conn; |
struct sftp_conn *conn; |
int err; |
int err, interactive; |
EditLine *el = NULL; |
EditLine *el = NULL; |
History *hl = NULL; |
History *hl = NULL; |
HistEvent hev; |
HistEvent hev; |
|
|
setvbuf(stdout, NULL, _IOLBF, 0); |
setvbuf(stdout, NULL, _IOLBF, 0); |
setvbuf(infile, NULL, _IOLBF, 0); |
setvbuf(infile, NULL, _IOLBF, 0); |
|
|
|
interactive = !batchmode && isatty(STDIN_FILENO); |
err = 0; |
err = 0; |
for (;;) { |
for (;;) { |
char *cp; |
char *cp; |
|
|
signal(SIGINT, SIG_IGN); |
signal(SIGINT, SIG_IGN); |
|
|
if (el == NULL) { |
if (el == NULL) { |
printf("sftp> "); |
if (interactive) |
|
printf("sftp> "); |
if (fgets(cmd, sizeof(cmd), infile) == NULL) { |
if (fgets(cmd, sizeof(cmd), infile) == NULL) { |
printf("\n"); |
if (interactive) |
|
printf("\n"); |
break; |
break; |
} |
} |
if (batchmode) /* Echo command */ |
if (!interactive) { /* Echo command */ |
printf("%s", cmd); |
printf("sftp> %s", cmd); |
|
if (strlen(cmd) > 0 && |
|
cmd[strlen(cmd) - 1] != '\n') |
|
printf("\n"); |
|
} |
} else { |
} else { |
if ((line = el_gets(el, &count)) == NULL || count <= 0) |
if ((line = el_gets(el, &count)) == NULL || count <= 0) { |
|
printf("\n"); |
break; |
break; |
|
} |
history(hl, &hev, H_ENTER, line); |
history(hl, &hev, H_ENTER, line); |
if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { |
if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { |
fprintf(stderr, "Error: input line too long\n"); |
fprintf(stderr, "Error: input line too long\n"); |
|
|
} |
} |
xfree(pwd); |
xfree(pwd); |
|
|
|
if (el != NULL) |
|
el_end(el); |
|
|
/* err == 1 signifies normal "quit" exit */ |
/* err == 1 signifies normal "quit" exit */ |
return (err >= 0 ? 0 : -1); |
return (err >= 0 ? 0 : -1); |
} |
} |
|
|
extern int optind; |
extern int optind; |
extern char *optarg; |
extern char *optarg; |
|
|
|
/* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ |
|
sanitise_stdfd(); |
|
|
|
memset(&args, '\0', sizeof(args)); |
args.list = NULL; |
args.list = NULL; |
addargs(&args, "ssh"); /* overwritten with ssh_program */ |
addargs(&args, ssh_program); |
addargs(&args, "-oForwardX11 no"); |
addargs(&args, "-oForwardX11 no"); |
addargs(&args, "-oForwardAgent no"); |
addargs(&args, "-oForwardAgent no"); |
|
addargs(&args, "-oPermitLocalCommand no"); |
addargs(&args, "-oClearAllForwardings yes"); |
addargs(&args, "-oClearAllForwardings yes"); |
|
|
ll = SYSLOG_LEVEL_INFO; |
ll = SYSLOG_LEVEL_INFO; |
|
|
break; |
break; |
case 'S': |
case 'S': |
ssh_program = optarg; |
ssh_program = optarg; |
|
replacearg(&args, 0, "%s", ssh_program); |
break; |
break; |
case 'b': |
case 'b': |
if (batchmode) |
if (batchmode) |
|
|
|
|
/* Allow "-" as stdin */ |
/* Allow "-" as stdin */ |
if (strcmp(optarg, "-") != 0 && |
if (strcmp(optarg, "-") != 0 && |
(infile = fopen(optarg, "r")) == NULL) |
(infile = fopen(optarg, "r")) == NULL) |
fatal("%s (%s).", strerror(errno), optarg); |
fatal("%s (%s).", strerror(errno), optarg); |
showprogress = 0; |
showprogress = 0; |
batchmode = 1; |
batchmode = 1; |
|
|
addargs(&args, "%s", host); |
addargs(&args, "%s", host); |
addargs(&args, "%s", (sftp_server != NULL ? |
addargs(&args, "%s", (sftp_server != NULL ? |
sftp_server : "sftp")); |
sftp_server : "sftp")); |
args.list[0] = ssh_program; |
|
|
|
if (!batchmode) |
if (!batchmode) |
fprintf(stderr, "Connecting to %s...\n", host); |
fprintf(stderr, "Connecting to %s...\n", host); |
|
|
fprintf(stderr, "Attaching to %s...\n", sftp_direct); |
fprintf(stderr, "Attaching to %s...\n", sftp_direct); |
connect_to_server(sftp_direct, args.list, &in, &out); |
connect_to_server(sftp_direct, args.list, &in, &out); |
} |
} |
|
freeargs(&args); |
|
|
err = interactive_loop(in, out, file1, file2); |
err = interactive_loop(in, out, file1, file2); |
|
|