cmdtab.c revision 142129
1/*	$NetBSD: cmdtab.c,v 1.43 2004/07/15 08:50:10 lukem 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.43 2004/07/15 08:50:10 lukem 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
84#define HSTR	static const char
85
86#ifndef NO_HELP
87HSTR	accounthelp[] =	"send account command to remote server";
88HSTR	appendhelp[] =	"append to a file";
89HSTR	asciihelp[] =	"set ascii transfer type";
90HSTR	beephelp[] =	"beep when command completed";
91HSTR	binaryhelp[] =	"set binary transfer type";
92HSTR	casehelp[] =	"toggle mget upper/lower case id mapping";
93HSTR	cdhelp[] =	"change remote working directory";
94HSTR	cduphelp[] =	"change remote working directory to parent directory";
95HSTR	chmodhelp[] =	"change file permissions of remote file";
96HSTR	connecthelp[] =	"connect to remote ftp server";
97HSTR	crhelp[] =	"toggle carriage return stripping on ascii gets";
98HSTR	debughelp[] =	"toggle/set debugging mode";
99HSTR	deletehelp[] =	"delete remote file";
100HSTR	disconhelp[] =	"terminate ftp session";
101HSTR	domachelp[] =	"execute macro";
102HSTR	edithelp[] =	"toggle command line editing";
103HSTR	epsv4help[] =	"toggle use of EPSV/EPRT on IPv4 ftp";
104HSTR	feathelp[] =	"show FEATures supported by remote system";
105HSTR	formhelp[] =	"set file transfer format";
106HSTR	gatehelp[] =	"toggle gate-ftp; specify host[:port] to change proxy";
107HSTR	globhelp[] =	"toggle metacharacter expansion of local file names";
108HSTR	hashhelp[] =	"toggle printing `#' marks; specify number to set size";
109HSTR	helphelp[] =	"print local help information";
110HSTR	idlehelp[] =	"get (set) idle timer on remote side";
111HSTR	lcdhelp[] =	"change local working directory";
112HSTR	lpagehelp[] =	"view a local file through your pager";
113HSTR	lpwdhelp[] =	"print local working directory";
114HSTR	lshelp[] =	"list contents of remote path";
115HSTR	macdefhelp[] =  "define a macro";
116HSTR	mdeletehelp[] =	"delete multiple files";
117HSTR	mgethelp[] =	"get multiple files";
118HSTR	mregethelp[] =	"get multiple files restarting at end of local file";
119HSTR	fgethelp[] =	"get files using a localfile as a source of names";
120HSTR	mkdirhelp[] =	"make directory on the remote machine";
121HSTR	mlshelp[] =	"list contents of multiple remote directories";
122HSTR	mlsdhelp[] =	"list contents of remote directory in a machine "
123			"parsable form";
124HSTR	mlsthelp[] =	"list remote path in a machine parsable form";
125HSTR	modehelp[] =	"set file transfer mode";
126HSTR	modtimehelp[] = "show last modification time of remote file";
127HSTR	mputhelp[] =	"send multiple files";
128HSTR	newerhelp[] =	"get file if remote file is newer than local file ";
129HSTR	nmaphelp[] =	"set templates for default file name mapping";
130HSTR	ntranshelp[] =	"set translation table for default file name mapping";
131HSTR	optshelp[] =	"show or set options for remote commands";
132HSTR	pagehelp[] =	"view a remote file through your pager";
133HSTR	passivehelp[] =	"toggle use of passive transfer mode";
134HSTR	plshelp[] =	"list contents of remote path through your pager";
135HSTR	pmlsdhelp[] =	"list contents of remote directory in a machine "
136			"parsable form through your pager";
137HSTR	porthelp[] =	"toggle use of PORT/LPRT cmd for each data connection";
138HSTR	preservehelp[] ="toggle preservation of modification time of "
139			"retrieved files";
140HSTR	progresshelp[] ="toggle transfer progress meter";
141HSTR	prompthelp[] =	"force interactive prompting on multiple commands";
142HSTR	proxyhelp[] =	"issue command on alternate connection";
143HSTR	pwdhelp[] =	"print working directory on remote machine";
144HSTR	quithelp[] =	"terminate ftp session and exit";
145HSTR	quotehelp[] =	"send arbitrary ftp command";
146HSTR	ratehelp[] =	"set transfer rate limit (in bytes/second)";
147HSTR	receivehelp[] =	"receive file";
148HSTR	regethelp[] =	"get file restarting at end of local file";
149HSTR	remotehelp[] =	"get help from remote server";
150HSTR	renamehelp[] =	"rename file";
151HSTR	resethelp[] =	"clear queued command replies";
152HSTR	restarthelp[]=	"restart file transfer at bytecount";
153HSTR	rmdirhelp[] =	"remove directory on the remote machine";
154HSTR	rmtstatushelp[]="show status of remote machine";
155HSTR	runiquehelp[] = "toggle store unique for local files";
156HSTR	sendhelp[] =	"send one file";
157HSTR	sethelp[] =	"set or display options";
158HSTR	shellhelp[] =	"escape to the shell";
159HSTR	sitehelp[] =	"send site specific command to remote server\n"
160			"\t\tTry \"rhelp site\" or \"site help\" "
161			"for more information";
162HSTR	sizecmdhelp[] = "show size of remote file";
163HSTR	statushelp[] =	"show current status";
164HSTR	structhelp[] =	"set file transfer structure";
165HSTR	suniquehelp[] = "toggle store unique on remote machine";
166HSTR	systemhelp[] =  "show remote system type";
167HSTR	tenexhelp[] =	"set tenex file transfer type";
168HSTR	tracehelp[] =	"toggle packet tracing";
169HSTR	typehelp[] =	"set file transfer type";
170HSTR	umaskhelp[] =	"get (set) umask on remote side";
171HSTR	unsethelp[] =	"unset an option";
172HSTR	usagehelp[] =	"show command usage";
173HSTR	userhelp[] =	"send new user information";
174HSTR	verbosehelp[] =	"toggle verbose mode";
175HSTR	xferbufhelp[] =	"set socket send/receive buffer size";
176#endif
177
178HSTR	empty[] = "";
179
180#ifdef NO_HELP
181#define H(x)	empty
182#else
183#define H(x)	x
184#endif
185
186#ifdef NO_EDITCOMPLETE
187#define	CMPL(x)
188#define	CMPL0
189#else  /* !NO_EDITCOMPLETE */
190#define	CMPL(x)	#x,
191#define	CMPL0	empty,
192#endif /* !NO_EDITCOMPLETE */
193
194struct cmd cmdtab[] = {
195	{ "!",		H(shellhelp),	0, 0, 0, CMPL0		shell },
196	{ "$",		H(domachelp),	1, 0, 0, CMPL0		domacro },
197	{ "account",	H(accounthelp),	0, 1, 1, CMPL0		account},
198	{ "append",	H(appendhelp),	1, 1, 1, CMPL(lr)	put },
199	{ "ascii",	H(asciihelp),	0, 1, 1, CMPL0		setascii },
200	{ "bell",	H(beephelp),	0, 0, 0, CMPL0		setbell },
201	{ "binary",	H(binaryhelp),	0, 1, 1, CMPL0		setbinary },
202	{ "bye",	H(quithelp),	0, 0, 0, CMPL0		quit },
203	{ "case",	H(casehelp),	0, 0, 1, CMPL0		setcase },
204	{ "cd",		H(cdhelp),	0, 1, 1, CMPL(r)	cd },
205	{ "cdup",	H(cduphelp),	0, 1, 1, CMPL0		cdup },
206	{ "chmod",	H(chmodhelp),	0, 1, 1, CMPL(nr)	do_chmod },
207	{ "close",	H(disconhelp),	0, 1, 1, CMPL0		disconnect },
208	{ "cr",		H(crhelp),	0, 0, 0, CMPL0		setcr },
209	{ "debug",	H(debughelp),	0, 0, 0, CMPL0		setdebug },
210	{ "delete",	H(deletehelp),	0, 1, 1, CMPL(r)	delete },
211	{ "dir",	H(lshelp),	1, 1, 1, CMPL(rl)	ls },
212	{ "disconnect",	H(disconhelp),	0, 1, 1, CMPL0		disconnect },
213	{ "edit",	H(edithelp),	0, 0, 0, CMPL0		setedit },
214	{ "epsv4",	H(epsv4help),	0, 0, 0, CMPL0		setepsv4 },
215	{ "exit",	H(quithelp),	0, 0, 0, CMPL0		quit },
216	{ "features",	H(feathelp),	0, 1, 1, CMPL0		feat },
217	{ "fget",	H(fgethelp),	1, 1, 1, CMPL(l)	fget },
218	{ "form",	H(formhelp),	0, 1, 1, CMPL0		setform },
219	{ "ftp",	H(connecthelp),	0, 0, 1, CMPL0		setpeer },
220	{ "gate",	H(gatehelp),	0, 0, 0, CMPL0		setgate },
221	{ "get",	H(receivehelp),	1, 1, 1, CMPL(rl)	get },
222	{ "glob",	H(globhelp),	0, 0, 0, CMPL0		setglob },
223	{ "hash",	H(hashhelp),	0, 0, 0, CMPL0		sethash },
224	{ "help",	H(helphelp),	0, 0, 1, CMPL(C)	help },
225	{ "idle",	H(idlehelp),	0, 1, 1, CMPL0		idlecmd },
226	{ "image",	H(binaryhelp),	0, 1, 1, CMPL0		setbinary },
227	{ "lcd",	H(lcdhelp),	0, 0, 0, CMPL(l)	lcd },
228	{ "less",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
229	{ "lpage",	H(lpagehelp),	0, 0, 0, CMPL(l)	lpage },
230	{ "lpwd",	H(lpwdhelp),	0, 0, 0, CMPL0		lpwd },
231	{ "ls",		H(lshelp),	1, 1, 1, CMPL(rl)	ls },
232	{ "macdef",	H(macdefhelp),	0, 0, 0, CMPL0		macdef },
233	{ "mdelete",	H(mdeletehelp),	1, 1, 1, CMPL(R)	mdelete },
234	{ "mdir",	H(mlshelp),	1, 1, 1, CMPL(R)	mls },
235	{ "mget",	H(mgethelp),	1, 1, 1, CMPL(R)	mget },
236	{ "mkdir",	H(mkdirhelp),	0, 1, 1, CMPL(r)	makedir },
237	{ "mls",	H(mlshelp),	1, 1, 1, CMPL(R)	mls },
238	{ "mlsd",	H(mlsdhelp),	1, 1, 1, CMPL(r)	ls },
239	{ "mlst",	H(mlsthelp),	1, 1, 1, CMPL(r)	mlst },
240	{ "mode",	H(modehelp),	0, 1, 1, CMPL0		setftmode },
241	{ "modtime",	H(modtimehelp),	0, 1, 1, CMPL(r)	modtime },
242	{ "more",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
243	{ "mput",	H(mputhelp),	1, 1, 1, CMPL(L)	mput },
244	{ "mreget",	H(mregethelp),	1, 1, 1, CMPL(R)	mget },
245	{ "msend",	H(mputhelp),	1, 1, 1, CMPL(L)	mput },
246	{ "newer",	H(newerhelp),	1, 1, 1, CMPL(r)	newer },
247	{ "nlist",	H(lshelp),	1, 1, 1, CMPL(rl)	ls },
248	{ "nmap",	H(nmaphelp),	0, 0, 1, CMPL0		setnmap },
249	{ "ntrans",	H(ntranshelp),	0, 0, 1, CMPL0		setntrans },
250	{ "open",	H(connecthelp),	0, 0, 1, CMPL0		setpeer },
251	{ "page",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
252	{ "passive",	H(passivehelp),	0, 0, 0, CMPL0		setpassive },
253	{ "pdir",	H(plshelp),	1, 1, 1, CMPL(r)	ls },
254	{ "pls",	H(plshelp),	1, 1, 1, CMPL(r)	ls },
255	{ "pmlsd",	H(pmlsdhelp),	1, 1, 1, CMPL(r)	ls },
256	{ "preserve",	H(preservehelp),0, 0, 0, CMPL0		setpreserve },
257	{ "progress",	H(progresshelp),0, 0, 0, CMPL0		setprogress },
258	{ "prompt",	H(prompthelp),	0, 0, 0, CMPL0		setprompt },
259	{ "proxy",	H(proxyhelp),	0, 0, 1, CMPL(c)	doproxy },
260	{ "put",	H(sendhelp),	1, 1, 1, CMPL(lr)	put },
261	{ "pwd",	H(pwdhelp),	0, 1, 1, CMPL0		pwd },
262	{ "quit",	H(quithelp),	0, 0, 0, CMPL0		quit },
263	{ "quote",	H(quotehelp),	1, 1, 1, CMPL0		quote },
264	{ "rate",	H(ratehelp),	0, 0, 0, CMPL0		setrate },
265	{ "rcvbuf",	H(xferbufhelp),	0, 0, 0, CMPL0		setxferbuf },
266	{ "recv",	H(receivehelp),	1, 1, 1, CMPL(rl)	get },
267	{ "reget",	H(regethelp),	1, 1, 1, CMPL(rl)	reget },
268	{ "remopts",	H(optshelp),	0, 1, 1, CMPL0		opts },
269	{ "rename",	H(renamehelp),	0, 1, 1, CMPL(rr)	renamefile },
270	{ "reset",	H(resethelp),	0, 1, 1, CMPL0		reset },
271	{ "restart",	H(restarthelp),	1, 1, 1, CMPL0		restart },
272	{ "rhelp",	H(remotehelp),	0, 1, 1, CMPL0		rmthelp },
273	{ "rmdir",	H(rmdirhelp),	0, 1, 1, CMPL(r)	removedir },
274	{ "rstatus",	H(rmtstatushelp),0, 1, 1, CMPL(r)	rmtstatus },
275	{ "runique",	H(runiquehelp),	0, 0, 1, CMPL0		setrunique },
276	{ "send",	H(sendhelp),	1, 1, 1, CMPL(lr)	put },
277	{ "sendport",	H(porthelp),	0, 0, 0, CMPL0		setport },
278	{ "set",	H(sethelp),	0, 0, 0, CMPL(o)	setoption },
279	{ "site",	H(sitehelp),	0, 1, 1, CMPL0		site },
280	{ "size",	H(sizecmdhelp),	1, 1, 1, CMPL(r)	sizecmd },
281	{ "sndbuf",	H(xferbufhelp),	0, 0, 0, CMPL0		setxferbuf },
282	{ "status",	H(statushelp),	0, 0, 1, CMPL0		status },
283	{ "struct",	H(structhelp),	0, 1, 1, CMPL0		setstruct },
284	{ "sunique",	H(suniquehelp),	0, 0, 1, CMPL0		setsunique },
285	{ "system",	H(systemhelp),	0, 1, 1, CMPL0		syst },
286	{ "tenex",	H(tenexhelp),	0, 1, 1, CMPL0		settenex },
287	{ "throttle",	H(ratehelp),	0, 0, 0, CMPL0		setrate },
288	{ "trace",	H(tracehelp),	0, 0, 0, CMPL0		settrace },
289	{ "type",	H(typehelp),	0, 1, 1, CMPL0		settype },
290	{ "umask",	H(umaskhelp),	0, 1, 1, CMPL0		do_umask },
291	{ "unset",	H(unsethelp),	0, 0, 0, CMPL(o)	unsetoption },
292	{ "usage",	H(usagehelp),	0, 0, 1, CMPL(C)	help },
293	{ "user",	H(userhelp),	0, 1, 1, CMPL0		user },
294	{ "verbose",	H(verbosehelp),	0, 0, 0, CMPL0		setverbose },
295	{ "xferbuf",	H(xferbufhelp),	0, 0, 0, CMPL0		setxferbuf },
296	{ "?",		H(helphelp),	0, 0, 1, CMPL(C)	help },
297	{ 0 },
298};
299
300struct option optiontab[] = {
301	{ "anonpass",	NULL },
302	{ "ftp_proxy",	NULL },
303	{ "http_proxy",	NULL },
304	{ "no_proxy",	NULL },
305	{ "pager",	NULL },
306	{ "prompt",	NULL },
307	{ "rprompt",	NULL },
308	{ 0 },
309};
310