cmdtab.c revision 121966
1/*	$NetBSD: cmdtab.c,v 1.41 2003/08/07 11:13:53 agc Exp $	*/
2
3/*-
4 * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Luke Mewburn.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the NetBSD
21 *	Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39/*
40 * Copyright (c) 1985, 1989, 1993, 1994
41 *	The Regents of the University of California.  All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 *    notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 *    notice, this list of conditions and the following disclaimer in the
50 *    documentation and/or other materials provided with the distribution.
51 * 3. Neither the name of the University nor the names of its contributors
52 *    may be used to endorse or promote products derived from this software
53 *    without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 */
67
68#include <sys/cdefs.h>
69#ifndef lint
70#if 0
71static char sccsid[] = "@(#)cmdtab.c	8.4 (Berkeley) 10/9/94";
72#else
73__RCSID("$NetBSD: cmdtab.c,v 1.41 2003/08/07 11:13:53 agc Exp $");
74#endif
75#endif /* not lint */
76
77#include <stdio.h>
78#include "ftp_var.h"
79
80/*
81 * User FTP -- Command Tables.
82 */
83
84char	accounthelp[] =	"send account command to remote server";
85char	appendhelp[] =	"append to a file";
86char	asciihelp[] =	"set ascii transfer type";
87char	beephelp[] =	"beep when command completed";
88char	binaryhelp[] =	"set binary transfer type";
89char	casehelp[] =	"toggle mget upper/lower case id mapping";
90char	cdhelp[] =	"change remote working directory";
91char	cduphelp[] =	"change remote working directory to parent directory";
92char	chmodhelp[] =	"change file permissions of remote file";
93char	connecthelp[] =	"connect to remote ftp server";
94char	crhelp[] =	"toggle carriage return stripping on ascii gets";
95char	debughelp[] =	"toggle/set debugging mode";
96char	deletehelp[] =	"delete remote file";
97char	disconhelp[] =	"terminate ftp session";
98char	domachelp[] =	"execute macro";
99char	edithelp[] =	"toggle command line editing";
100char	epsv4help[] =	"toggle use of EPSV/EPRT on IPv4 ftp";
101char	feathelp[] =	"show FEATures supported by remote system";
102char	formhelp[] =	"set file transfer format";
103char	gatehelp[] =	"toggle gate-ftp; specify host[:port] to change proxy";
104char	globhelp[] =	"toggle metacharacter expansion of local file names";
105char	hashhelp[] =	"toggle printing `#' marks; specify number to set size";
106char	helphelp[] =	"print local help information";
107char	idlehelp[] =	"get (set) idle timer on remote side";
108char	lcdhelp[] =	"change local working directory";
109char	lpagehelp[] =	"view a local file through your pager";
110char	lpwdhelp[] =	"print local working directory";
111char	lshelp[] =	"list contents of remote path";
112char	macdefhelp[] =  "define a macro";
113char	mdeletehelp[] =	"delete multiple files";
114char	mgethelp[] =	"get multiple files";
115char	mregethelp[] =	"get multiple files restarting at end of local file";
116char	fgethelp[] =	"get files using a localfile as a source of names";
117char	mkdirhelp[] =	"make directory on the remote machine";
118char	mlshelp[] =	"list contents of multiple remote directories";
119char	mlsdhelp[] =	"list contents of remote directory in a machine "
120			"parsable form";
121char	mlsthelp[] =	"list remote path in a machine parsable form";
122char	modehelp[] =	"set file transfer mode";
123char	modtimehelp[] = "show last modification time of remote file";
124char	mputhelp[] =	"send multiple files";
125char	newerhelp[] =	"get file if remote file is newer than local file ";
126char	nmaphelp[] =	"set templates for default file name mapping";
127char	ntranshelp[] =	"set translation table for default file name mapping";
128char	optshelp[] =	"show or set options for remote commands";
129char	pagehelp[] =	"view a remote file through your pager";
130char	passivehelp[] =	"toggle use of passive transfer mode";
131char	plshelp[] =	"list contents of remote path through your pager";
132char	pmlsdhelp[] =	"list contents of remote directory in a machine "
133			"parsable form through your pager";
134char	porthelp[] =	"toggle use of PORT/LPRT cmd for each data connection";
135char	preservehelp[] ="toggle preservation of modification time of "
136			"retrieved files";
137char	progresshelp[] ="toggle transfer progress meter";
138char	prompthelp[] =	"force interactive prompting on multiple commands";
139char	proxyhelp[] =	"issue command on alternate connection";
140char	pwdhelp[] =	"print working directory on remote machine";
141char	quithelp[] =	"terminate ftp session and exit";
142char	quotehelp[] =	"send arbitrary ftp command";
143char	ratehelp[] =	"set transfer rate limit (in bytes/second)";
144char	receivehelp[] =	"receive file";
145char	regethelp[] =	"get file restarting at end of local file";
146char	remotehelp[] =	"get help from remote server";
147char	renamehelp[] =	"rename file";
148char	resethelp[] =	"clear queued command replies";
149char	restarthelp[]=	"restart file transfer at bytecount";
150char	rmdirhelp[] =	"remove directory on the remote machine";
151char	rmtstatushelp[]="show status of remote machine";
152char	runiquehelp[] = "toggle store unique for local files";
153char	sendhelp[] =	"send one file";
154char	sethelp[] =	"set or display options";
155char	shellhelp[] =	"escape to the shell";
156char	sitehelp[] =	"send site specific command to remote server\n"
157			"\t\tTry \"rhelp site\" or \"site help\" "
158			"for more information";
159char	sizecmdhelp[] = "show size of remote file";
160char	statushelp[] =	"show current status";
161char	structhelp[] =	"set file transfer structure";
162char	suniquehelp[] = "toggle store unique on remote machine";
163char	systemhelp[] =  "show remote system type";
164char	tenexhelp[] =	"set tenex file transfer type";
165char	tracehelp[] =	"toggle packet tracing";
166char	typehelp[] =	"set file transfer type";
167char	umaskhelp[] =	"get (set) umask on remote side";
168char	unsethelp[] =	"unset an option";
169char	usagehelp[] =	"show command usage";
170char	userhelp[] =	"send new user information";
171char	verbosehelp[] =	"toggle verbose mode";
172char	xferbufhelp[] =	"set socket send/receive buffer size";
173
174#ifdef NO_EDITCOMPLETE
175#define	CMPL(x)
176#define	CMPL0
177#else  /* !NO_EDITCOMPLETE */
178#define	CMPL(x)	#x,
179#define	CMPL0	"",
180#endif /* !NO_EDITCOMPLETE */
181
182struct cmd cmdtab[] = {
183	{ "!",		shellhelp,	0, 0, 0, CMPL0		shell },
184	{ "$",		domachelp,	1, 0, 0, CMPL0		domacro },
185	{ "account",	accounthelp,	0, 1, 1, CMPL0		account},
186	{ "append",	appendhelp,	1, 1, 1, CMPL(lr)	put },
187	{ "ascii",	asciihelp,	0, 1, 1, CMPL0		setascii },
188	{ "bell",	beephelp,	0, 0, 0, CMPL0		setbell },
189	{ "binary",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
190	{ "bye",	quithelp,	0, 0, 0, CMPL0		quit },
191	{ "case",	casehelp,	0, 0, 1, CMPL0		setcase },
192	{ "cd",		cdhelp,		0, 1, 1, CMPL(r)	cd },
193	{ "cdup",	cduphelp,	0, 1, 1, CMPL0		cdup },
194	{ "chmod",	chmodhelp,	0, 1, 1, CMPL(nr)	do_chmod },
195	{ "close",	disconhelp,	0, 1, 1, CMPL0		disconnect },
196	{ "cr",		crhelp,		0, 0, 0, CMPL0		setcr },
197	{ "debug",	debughelp,	0, 0, 0, CMPL0		setdebug },
198	{ "delete",	deletehelp,	0, 1, 1, CMPL(r)	delete },
199	{ "dir",	lshelp,		1, 1, 1, CMPL(rl)	ls },
200	{ "disconnect",	disconhelp,	0, 1, 1, CMPL0		disconnect },
201	{ "edit",	edithelp,	0, 0, 0, CMPL0		setedit },
202	{ "epsv4",	epsv4help,	0, 0, 0, CMPL0		setepsv4 },
203	{ "exit",	quithelp,	0, 0, 0, CMPL0		quit },
204	{ "features",	feathelp,	0, 1, 1, CMPL0		feat },
205	{ "fget",	fgethelp,	1, 1, 1, CMPL(l)	fget },
206	{ "form",	formhelp,	0, 1, 1, CMPL0		setform },
207	{ "ftp",	connecthelp,	0, 0, 1, CMPL0		setpeer },
208	{ "gate",	gatehelp,	0, 0, 0, CMPL0		setgate },
209	{ "get",	receivehelp,	1, 1, 1, CMPL(rl)	get },
210	{ "glob",	globhelp,	0, 0, 0, CMPL0		setglob },
211	{ "hash",	hashhelp,	0, 0, 0, CMPL0		sethash },
212	{ "help",	helphelp,	0, 0, 1, CMPL(C)	help },
213	{ "idle",	idlehelp,	0, 1, 1, CMPL0		idlecmd },
214	{ "image",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
215	{ "lcd",	lcdhelp,	0, 0, 0, CMPL(l)	lcd },
216	{ "less",	pagehelp,	1, 1, 1, CMPL(r)	page },
217	{ "lpage",	lpagehelp,	0, 0, 0, CMPL(l)	lpage },
218	{ "lpwd",	lpwdhelp,	0, 0, 0, CMPL0		lpwd },
219	{ "ls",		lshelp,		1, 1, 1, CMPL(rl)	ls },
220	{ "macdef",	macdefhelp,	0, 0, 0, CMPL0		macdef },
221	{ "mdelete",	mdeletehelp,	1, 1, 1, CMPL(R)	mdelete },
222	{ "mdir",	mlshelp,	1, 1, 1, CMPL(R)	mls },
223	{ "mget",	mgethelp,	1, 1, 1, CMPL(R)	mget },
224	{ "mkdir",	mkdirhelp,	0, 1, 1, CMPL(r)	makedir },
225	{ "mls",	mlshelp,	1, 1, 1, CMPL(R)	mls },
226	{ "mlsd",	mlsdhelp,	1, 1, 1, CMPL(r)	ls },
227	{ "mlst",	mlsthelp,	1, 1, 1, CMPL(r)	mlst },
228	{ "mode",	modehelp,	0, 1, 1, CMPL0		setftmode },
229	{ "modtime",	modtimehelp,	0, 1, 1, CMPL(r)	modtime },
230	{ "more",	pagehelp,	1, 1, 1, CMPL(r)	page },
231	{ "mput",	mputhelp,	1, 1, 1, CMPL(L)	mput },
232	{ "mreget",	mregethelp,	1, 1, 1, CMPL(R)	mget },
233	{ "msend",	mputhelp,	1, 1, 1, CMPL(L)	mput },
234	{ "newer",	newerhelp,	1, 1, 1, CMPL(r)	newer },
235	{ "nlist",	lshelp,		1, 1, 1, CMPL(rl)	ls },
236	{ "nmap",	nmaphelp,	0, 0, 1, CMPL0		setnmap },
237	{ "ntrans",	ntranshelp,	0, 0, 1, CMPL0		setntrans },
238	{ "open",	connecthelp,	0, 0, 1, CMPL0		setpeer },
239	{ "page",	pagehelp,	1, 1, 1, CMPL(r)	page },
240	{ "passive",	passivehelp,	0, 0, 0, CMPL0		setpassive },
241	{ "pdir",	plshelp,	1, 1, 1, CMPL(r)	ls },
242	{ "pls",	plshelp,	1, 1, 1, CMPL(r)	ls },
243	{ "pmlsd",	pmlsdhelp,	1, 1, 1, CMPL(r)	ls },
244	{ "preserve",	preservehelp,	0, 0, 0, CMPL0		setpreserve },
245	{ "progress",	progresshelp,	0, 0, 0, CMPL0		setprogress },
246	{ "prompt",	prompthelp,	0, 0, 0, CMPL0		setprompt },
247	{ "proxy",	proxyhelp,	0, 0, 1, CMPL(c)	doproxy },
248	{ "put",	sendhelp,	1, 1, 1, CMPL(lr)	put },
249	{ "pwd",	pwdhelp,	0, 1, 1, CMPL0		pwd },
250	{ "quit",	quithelp,	0, 0, 0, CMPL0		quit },
251	{ "quote",	quotehelp,	1, 1, 1, CMPL0		quote },
252	{ "rate",	ratehelp,	0, 0, 0, CMPL0		setrate },
253	{ "rcvbuf",	xferbufhelp,	0, 0, 0, CMPL0		setxferbuf },
254	{ "recv",	receivehelp,	1, 1, 1, CMPL(rl)	get },
255	{ "reget",	regethelp,	1, 1, 1, CMPL(rl)	reget },
256	{ "remopts",	optshelp,	0, 1, 1, CMPL0		opts },
257	{ "rename",	renamehelp,	0, 1, 1, CMPL(rr)	renamefile },
258	{ "reset",	resethelp,	0, 1, 1, CMPL0		reset },
259	{ "restart",	restarthelp,	1, 1, 1, CMPL0		restart },
260	{ "rhelp",	remotehelp,	0, 1, 1, CMPL0		rmthelp },
261	{ "rmdir",	rmdirhelp,	0, 1, 1, CMPL(r)	removedir },
262	{ "rstatus",	rmtstatushelp,	0, 1, 1, CMPL(r)	rmtstatus },
263	{ "runique",	runiquehelp,	0, 0, 1, CMPL0		setrunique },
264	{ "send",	sendhelp,	1, 1, 1, CMPL(lr)	put },
265	{ "sendport",	porthelp,	0, 0, 0, CMPL0		setport },
266	{ "set",	sethelp,	0, 0, 0, CMPL(o)	setoption },
267	{ "site",	sitehelp,	0, 1, 1, CMPL0		site },
268	{ "size",	sizecmdhelp,	1, 1, 1, CMPL(r)	sizecmd },
269	{ "sndbuf",	xferbufhelp,	0, 0, 0, CMPL0		setxferbuf },
270	{ "status",	statushelp,	0, 0, 1, CMPL0		status },
271	{ "struct",	structhelp,	0, 1, 1, CMPL0		setstruct },
272	{ "sunique",	suniquehelp,	0, 0, 1, CMPL0		setsunique },
273	{ "system",	systemhelp,	0, 1, 1, CMPL0		syst },
274	{ "tenex",	tenexhelp,	0, 1, 1, CMPL0		settenex },
275	{ "throttle",	ratehelp,	0, 0, 0, CMPL0		setrate },
276	{ "trace",	tracehelp,	0, 0, 0, CMPL0		settrace },
277	{ "type",	typehelp,	0, 1, 1, CMPL0		settype },
278	{ "umask",	umaskhelp,	0, 1, 1, CMPL0		do_umask },
279	{ "unset",	unsethelp,	0, 0, 0, CMPL(o)	unsetoption },
280	{ "usage",	usagehelp,	0, 0, 1, CMPL(C)	help },
281	{ "user",	userhelp,	0, 1, 1, CMPL0		user },
282	{ "verbose",	verbosehelp,	0, 0, 0, CMPL0		setverbose },
283	{ "xferbuf",	xferbufhelp,	0, 0, 0, CMPL0		setxferbuf },
284	{ "?",		helphelp,	0, 0, 1, CMPL(C)	help },
285	{ 0 },
286};
287
288struct option optiontab[] = {
289	{ "anonpass",	NULL },
290	{ "ftp_proxy",	NULL },
291	{ "http_proxy",	NULL },
292	{ "no_proxy",	NULL },
293	{ "pager",	NULL },
294	{ "prompt",	NULL },
295	{ "rprompt",	NULL },
296	{ 0 },
297};
298