xref: /netbsd-src/usr.bin/ftp/cmdtab.c (revision da5f4674a3fc214be3572d358b66af40ab9401e7)
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
71 static 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 
84 char	accounthelp[] =	"send account command to remote server";
85 char	appendhelp[] =	"append to a file";
86 char	asciihelp[] =	"set ascii transfer type";
87 char	beephelp[] =	"beep when command completed";
88 char	binaryhelp[] =	"set binary transfer type";
89 char	casehelp[] =	"toggle mget upper/lower case id mapping";
90 char	cdhelp[] =	"change remote working directory";
91 char	cduphelp[] =	"change remote working directory to parent directory";
92 char	chmodhelp[] =	"change file permissions of remote file";
93 char	connecthelp[] =	"connect to remote ftp server";
94 char	crhelp[] =	"toggle carriage return stripping on ascii gets";
95 char	debughelp[] =	"toggle/set debugging mode";
96 char	deletehelp[] =	"delete remote file";
97 char	disconhelp[] =	"terminate ftp session";
98 char	domachelp[] =	"execute macro";
99 char	edithelp[] =	"toggle command line editing";
100 char	epsv4help[] =	"toggle use of EPSV/EPRT on IPv4 ftp";
101 char	feathelp[] =	"show FEATures supported by remote system";
102 char	formhelp[] =	"set file transfer format";
103 char	gatehelp[] =	"toggle gate-ftp; specify host[:port] to change proxy";
104 char	globhelp[] =	"toggle metacharacter expansion of local file names";
105 char	hashhelp[] =	"toggle printing `#' marks; specify number to set size";
106 char	helphelp[] =	"print local help information";
107 char	idlehelp[] =	"get (set) idle timer on remote side";
108 char	lcdhelp[] =	"change local working directory";
109 char	lpagehelp[] =	"view a local file through your pager";
110 char	lpwdhelp[] =	"print local working directory";
111 char	lshelp[] =	"list contents of remote path";
112 char	macdefhelp[] =  "define a macro";
113 char	mdeletehelp[] =	"delete multiple files";
114 char	mgethelp[] =	"get multiple files";
115 char	mregethelp[] =	"get multiple files restarting at end of local file";
116 char	fgethelp[] =	"get files using a localfile as a source of names";
117 char	mkdirhelp[] =	"make directory on the remote machine";
118 char	mlshelp[] =	"list contents of multiple remote directories";
119 char	mlsdhelp[] =	"list contents of remote directory in a machine "
120 			"parsable form";
121 char	mlsthelp[] =	"list remote path in a machine parsable form";
122 char	modehelp[] =	"set file transfer mode";
123 char	modtimehelp[] = "show last modification time of remote file";
124 char	mputhelp[] =	"send multiple files";
125 char	newerhelp[] =	"get file if remote file is newer than local file ";
126 char	nmaphelp[] =	"set templates for default file name mapping";
127 char	ntranshelp[] =	"set translation table for default file name mapping";
128 char	optshelp[] =	"show or set options for remote commands";
129 char	pagehelp[] =	"view a remote file through your pager";
130 char	passivehelp[] =	"toggle use of passive transfer mode";
131 char	plshelp[] =	"list contents of remote path through your pager";
132 char	pmlsdhelp[] =	"list contents of remote directory in a machine "
133 			"parsable form through your pager";
134 char	porthelp[] =	"toggle use of PORT/LPRT cmd for each data connection";
135 char	preservehelp[] ="toggle preservation of modification time of "
136 			"retrieved files";
137 char	progresshelp[] ="toggle transfer progress meter";
138 char	prompthelp[] =	"force interactive prompting on multiple commands";
139 char	proxyhelp[] =	"issue command on alternate connection";
140 char	pwdhelp[] =	"print working directory on remote machine";
141 char	quithelp[] =	"terminate ftp session and exit";
142 char	quotehelp[] =	"send arbitrary ftp command";
143 char	ratehelp[] =	"set transfer rate limit (in bytes/second)";
144 char	receivehelp[] =	"receive file";
145 char	regethelp[] =	"get file restarting at end of local file";
146 char	remotehelp[] =	"get help from remote server";
147 char	renamehelp[] =	"rename file";
148 char	resethelp[] =	"clear queued command replies";
149 char	restarthelp[]=	"restart file transfer at bytecount";
150 char	rmdirhelp[] =	"remove directory on the remote machine";
151 char	rmtstatushelp[]="show status of remote machine";
152 char	runiquehelp[] = "toggle store unique for local files";
153 char	sendhelp[] =	"send one file";
154 char	sethelp[] =	"set or display options";
155 char	shellhelp[] =	"escape to the shell";
156 char	sitehelp[] =	"send site specific command to remote server\n"
157 			"\t\tTry \"rhelp site\" or \"site help\" "
158 			"for more information";
159 char	sizecmdhelp[] = "show size of remote file";
160 char	statushelp[] =	"show current status";
161 char	structhelp[] =	"set file transfer structure";
162 char	suniquehelp[] = "toggle store unique on remote machine";
163 char	systemhelp[] =  "show remote system type";
164 char	tenexhelp[] =	"set tenex file transfer type";
165 char	tracehelp[] =	"toggle packet tracing";
166 char	typehelp[] =	"set file transfer type";
167 char	umaskhelp[] =	"get (set) umask on remote side";
168 char	unsethelp[] =	"unset an option";
169 char	usagehelp[] =	"show command usage";
170 char	userhelp[] =	"send new user information";
171 char	verbosehelp[] =	"toggle verbose mode";
172 char	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 
182 struct 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 
288 struct 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