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