View | Details | Raw Unified | Return to bug 2760
Collapse All | Expand All

(-)a/sftp.1 (-2 / +8 lines)
Lines 301-309 must be escaped with backslashes Link Here
301
.It Ic bye
301
.It Ic bye
302
Quit
302
Quit
303
.Nm sftp .
303
.Nm sftp .
304
.It Ic cd Ar path
304
.It Ic cd Op Ar path
305
Change remote directory to
305
Change remote directory to
306
.Ar path .
306
.Ar path .
307
If
308
.Ar path
309
is not specified, then change directory to the one the session started in.
307
.It Ic chgrp Ar grp Ar path
310
.It Ic chgrp Ar grp Ar path
308
Change group of file
311
Change group of file
309
.Ar path
312
.Ar path
Lines 407-415 Note that Link Here
407
does not follow symbolic links when performing recursive transfers.
410
does not follow symbolic links when performing recursive transfers.
408
.It Ic help
411
.It Ic help
409
Display help text.
412
Display help text.
410
.It Ic lcd Ar path
413
.It Ic lcd Op Ar path
411
Change local directory to
414
Change local directory to
412
.Ar path .
415
.Ar path .
416
If
417
.Ar path
418
is not specified, then change directory to the local user's home directory.
413
.It Ic lls Op Ar ls-options Op Ar path
419
.It Ic lls Op Ar ls-options Op Ar path
414
Display local directory listing of either
420
Display local directory listing of either
415
.Ar path
421
.Ar path
(-)a/sftp.c (-10 / +20 lines)
Lines 195-202 static const struct CMD cmds[] = { Link Here
195
	{ NULL,		-1,		-1	}
195
	{ NULL,		-1,		-1	}
196
};
196
};
197
197
198
int interactive_loop(struct sftp_conn *, char *file1, char *file2);
199
200
/* ARGSUSED */
198
/* ARGSUSED */
201
static void
199
static void
202
killchild(int signo)
200
killchild(int signo)
Lines 1260-1266 parse_args(const char **cpp, int *ignore_errors, int *aflag, Link Here
1260
	char *cp2, **argv;
1258
	char *cp2, **argv;
1261
	int base = 0;
1259
	int base = 0;
1262
	long l;
1260
	long l;
1263
	int i, cmdnum, optidx, argc;
1261
	int path1_mandatory = 0, i, cmdnum, optidx, argc;
1264
1262
1265
	/* Skip leading whitespace */
1263
	/* Skip leading whitespace */
1266
	cp = cp + strspn(cp, WHITESPACE);
1264
	cp = cp + strspn(cp, WHITESPACE);
Lines 1350-1362 parse_args(const char **cpp, int *ignore_errors, int *aflag, Link Here
1350
	case I_RM:
1348
	case I_RM:
1351
	case I_MKDIR:
1349
	case I_MKDIR:
1352
	case I_RMDIR:
1350
	case I_RMDIR:
1351
	case I_LMKDIR:
1352
		path1_mandatory = 1;
1353
		/* FALLTHROUGH */
1353
	case I_CHDIR:
1354
	case I_CHDIR:
1354
	case I_LCHDIR:
1355
	case I_LCHDIR:
1355
	case I_LMKDIR:
1356
		if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
1356
		if ((optidx = parse_no_flags(cmd, argv, argc)) == -1)
1357
			return -1;
1357
			return -1;
1358
		/* Get pathname (mandatory) */
1358
		/* Get pathname (mandatory) */
1359
		if (argc - optidx < 1) {
1359
		if (argc - optidx < 1) {
1360
			if (!path1_mandatory)
1361
				break; /* return a NULL path1 */
1360
			error("You must specify a path after a %s command.",
1362
			error("You must specify a path after a %s command.",
1361
			    cmd);
1363
			    cmd);
1362
			return -1;
1364
			return -1;
Lines 1441-1447 parse_args(const char **cpp, int *ignore_errors, int *aflag, Link Here
1441
1443
1442
static int
1444
static int
1443
parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
1445
parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
1444
    int err_abort)
1446
    const char *startdir, int err_abort)
1445
{
1447
{
1446
	char *path1, *path2, *tmp;
1448
	char *path1, *path2, *tmp;
1447
	int ignore_errors = 0, aflag = 0, fflag = 0, hflag = 0,
1449
	int ignore_errors = 0, aflag = 0, fflag = 0, hflag = 0,
Lines 1521-1526 parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, Link Here
1521
		err = do_rmdir(conn, path1);
1523
		err = do_rmdir(conn, path1);
1522
		break;
1524
		break;
1523
	case I_CHDIR:
1525
	case I_CHDIR:
1526
		if (path1 == NULL || *path1 == '\0')
1527
			path1 = xstrdup(startdir);
1524
		path1 = make_absolute(path1, *pwd);
1528
		path1 = make_absolute(path1, *pwd);
1525
		if ((tmp = do_realpath(conn, path1)) == NULL) {
1529
		if ((tmp = do_realpath(conn, path1)) == NULL) {
1526
			err = 1;
1530
			err = 1;
Lines 1569-1574 parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, Link Here
1569
		err = do_df(conn, path1, hflag, iflag);
1573
		err = do_df(conn, path1, hflag, iflag);
1570
		break;
1574
		break;
1571
	case I_LCHDIR:
1575
	case I_LCHDIR:
1576
		if (path1 == NULL || *path1 == '\0')
1577
			path1 = xstrdup("~");
1572
		tmp = tilde_expand_filename(path1, getuid());
1578
		tmp = tilde_expand_filename(path1, getuid());
1573
		free(path1);
1579
		free(path1);
1574
		path1 = tmp;
1580
		path1 = tmp;
Lines 2053-2063 complete(EditLine *el, int ch) Link Here
2053
	return ret;
2059
	return ret;
2054
}
2060
}
2055
2061
2056
int
2062
static int
2057
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
2063
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
2058
{
2064
{
2059
	char *remote_path;
2065
	char *remote_path;
2060
	char *dir = NULL;
2066
	char *dir = NULL, *startdir = NULL;
2061
	char cmd[2048];
2067
	char cmd[2048];
2062
	int err, interactive;
2068
	int err, interactive;
2063
	EditLine *el = NULL;
2069
	EditLine *el = NULL;
Lines 2099-2104 interactive_loop(struct sftp_conn *conn, char *file1, char *file2) Link Here
2099
	remote_path = do_realpath(conn, ".");
2105
	remote_path = do_realpath(conn, ".");
2100
	if (remote_path == NULL)
2106
	if (remote_path == NULL)
2101
		fatal("Need cwd");
2107
		fatal("Need cwd");
2108
	startdir = xstrdup(remote_path);
2102
2109
2103
	if (file1 != NULL) {
2110
	if (file1 != NULL) {
2104
		dir = xstrdup(file1);
2111
		dir = xstrdup(file1);
Lines 2109-2116 interactive_loop(struct sftp_conn *conn, char *file1, char *file2) Link Here
2109
				mprintf("Changing to: %s\n", dir);
2116
				mprintf("Changing to: %s\n", dir);
2110
			snprintf(cmd, sizeof cmd, "cd \"%s\"", dir);
2117
			snprintf(cmd, sizeof cmd, "cd \"%s\"", dir);
2111
			if (parse_dispatch_command(conn, cmd,
2118
			if (parse_dispatch_command(conn, cmd,
2112
			    &remote_path, 1) != 0) {
2119
			    &remote_path, startdir, 1) != 0) {
2113
				free(dir);
2120
				free(dir);
2121
				free(startdir);
2114
				free(remote_path);
2122
				free(remote_path);
2115
				free(conn);
2123
				free(conn);
2116
				return (-1);
2124
				return (-1);
Lines 2122-2129 interactive_loop(struct sftp_conn *conn, char *file1, char *file2) Link Here
2122
			    file2 == NULL ? "" : " ",
2130
			    file2 == NULL ? "" : " ",
2123
			    file2 == NULL ? "" : file2);
2131
			    file2 == NULL ? "" : file2);
2124
			err = parse_dispatch_command(conn, cmd,
2132
			err = parse_dispatch_command(conn, cmd,
2125
			    &remote_path, 1);
2133
			    &remote_path, startdir, 1);
2126
			free(dir);
2134
			free(dir);
2135
			free(startdir);
2127
			free(remote_path);
2136
			free(remote_path);
2128
			free(conn);
2137
			free(conn);
2129
			return (err);
2138
			return (err);
Lines 2179-2189 interactive_loop(struct sftp_conn *conn, char *file1, char *file2) Link Here
2179
		signal(SIGINT, cmd_interrupt);
2188
		signal(SIGINT, cmd_interrupt);
2180
2189
2181
		err = parse_dispatch_command(conn, cmd, &remote_path,
2190
		err = parse_dispatch_command(conn, cmd, &remote_path,
2182
		    batchmode);
2191
		    startdir, batchmode);
2183
		if (err != 0)
2192
		if (err != 0)
2184
			break;
2193
			break;
2185
	}
2194
	}
2186
	free(remote_path);
2195
	free(remote_path);
2196
	free(startdir);
2187
	free(conn);
2197
	free(conn);
2188
2198
2189
	if (el != NULL)
2199
	if (el != NULL)

Return to bug 2760