cmdtab.c revision 121966
190075Sobrien/*	$NetBSD: cmdtab.c,v 1.41 2003/08/07 11:13:53 agc Exp $	*/
290075Sobrien
3169689Skan/*-
4169689Skan * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
590075Sobrien * All rights reserved.
6132718Skan *
790075Sobrien * This code is derived from software contributed to The NetBSD Foundation
8132718Skan * by Luke Mewburn.
9132718Skan *
10132718Skan * Redistribution and use in source and binary forms, with or without
11132718Skan * modification, are permitted provided that the following conditions
1290075Sobrien * are met:
13132718Skan * 1. Redistributions of source code must retain the above copyright
14132718Skan *    notice, this list of conditions and the following disclaimer.
15132718Skan * 2. Redistributions in binary form must reproduce the above copyright
16132718Skan *    notice, this list of conditions and the following disclaimer in the
1790075Sobrien *    documentation and/or other materials provided with the distribution.
18132718Skan * 3. All advertising materials mentioning features or use of this software
19132718Skan *    must display the following acknowledgement:
20169689Skan *	This product includes software developed by the NetBSD
21169689Skan *	Foundation, Inc. and its contributors.
2290075Sobrien * 4. Neither the name of The NetBSD Foundation nor the names of its
2390075Sobrien *    contributors may be used to endorse or promote products derived
2490075Sobrien *    from this software without specific prior written permission.
25117395Skan *
2690075Sobrien * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27117395Skan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28117395Skan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29117395Skan * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30117395Skan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31117395Skan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32117395Skan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33117395Skan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34117395Skan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35117395Skan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36169689Skan * POSSIBILITY OF SUCH DAMAGE.
37169689Skan */
38169689Skan
39169689Skan/*
40117395Skan * Copyright (c) 1985, 1989, 1993, 1994
41117395Skan *	The Regents of the University of California.  All rights reserved.
42117395Skan *
43117395Skan * Redistribution and use in source and binary forms, with or without
44117395Skan * modification, are permitted provided that the following conditions
45169689Skan * are met:
46169689Skan * 1. Redistributions of source code must retain the above copyright
47117395Skan *    notice, this list of conditions and the following disclaimer.
4890075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
4990075Sobrien *    notice, this list of conditions and the following disclaimer in the
5090075Sobrien *    documentation and/or other materials provided with the distribution.
5190075Sobrien * 3. Neither the name of the University nor the names of its contributors
5296263Sobrien *    may be used to endorse or promote products derived from this software
53117395Skan *    without specific prior written permission.
5496263Sobrien *
5590075Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5690075Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5790075Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5890075Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59169689Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
6090075Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
6190075Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
6290075Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
6390075Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6490075Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6590075Sobrien * SUCH DAMAGE.
66169689Skan */
67169689Skan
68169689Skan#include <sys/cdefs.h>
69169689Skan#ifndef lint
70169689Skan#if 0
71169689Skanstatic char sccsid[] = "@(#)cmdtab.c	8.4 (Berkeley) 10/9/94";
72169689Skan#else
73169689Skan__RCSID("$NetBSD: cmdtab.c,v 1.41 2003/08/07 11:13:53 agc Exp $");
74169689Skan#endif
75169689Skan#endif /* not lint */
76169689Skan
77169689Skan#include <stdio.h>
78169689Skan#include "ftp_var.h"
79169689Skan
80169689Skan/*
81169689Skan * User FTP -- Command Tables.
82169689Skan */
83169689Skan
84169689Skanchar	accounthelp[] =	"send account command to remote server";
85169689Skanchar	appendhelp[] =	"append to a file";
86169689Skanchar	asciihelp[] =	"set ascii transfer type";
87169689Skanchar	beephelp[] =	"beep when command completed";
88169689Skanchar	binaryhelp[] =	"set binary transfer type";
89169689Skanchar	casehelp[] =	"toggle mget upper/lower case id mapping";
9090075Sobrienchar	cdhelp[] =	"change remote working directory";
91169689Skanchar	cduphelp[] =	"change remote working directory to parent directory";
92169689Skanchar	chmodhelp[] =	"change file permissions of remote file";
93169689Skanchar	connecthelp[] =	"connect to remote ftp server";
94169689Skanchar	crhelp[] =	"toggle carriage return stripping on ascii gets";
95169689Skanchar	debughelp[] =	"toggle/set debugging mode";
96169689Skanchar	deletehelp[] =	"delete remote file";
97169689Skanchar	disconhelp[] =	"terminate ftp session";
98169689Skanchar	domachelp[] =	"execute macro";
99169689Skanchar	edithelp[] =	"toggle command line editing";
100169689Skanchar	epsv4help[] =	"toggle use of EPSV/EPRT on IPv4 ftp";
101169689Skanchar	feathelp[] =	"show FEATures supported by remote system";
102169689Skanchar	formhelp[] =	"set file transfer format";
103169689Skanchar	gatehelp[] =	"toggle gate-ftp; specify host[:port] to change proxy";
104169689Skanchar	globhelp[] =	"toggle metacharacter expansion of local file names";
105117395Skanchar	hashhelp[] =	"toggle printing `#' marks; specify number to set size";
10690075Sobrienchar	helphelp[] =	"print local help information";
10790075Sobrienchar	idlehelp[] =	"get (set) idle timer on remote side";
10890075Sobrienchar	lcdhelp[] =	"change local working directory";
10990075Sobrienchar	lpagehelp[] =	"view a local file through your pager";
11090075Sobrienchar	lpwdhelp[] =	"print local working directory";
111117395Skanchar	lshelp[] =	"list contents of remote path";
11290075Sobrienchar	macdefhelp[] =  "define a macro";
11390075Sobrienchar	mdeletehelp[] =	"delete multiple files";
11490075Sobrienchar	mgethelp[] =	"get multiple files";
11590075Sobrienchar	mregethelp[] =	"get multiple files restarting at end of local file";
11690075Sobrienchar	fgethelp[] =	"get files using a localfile as a source of names";
11790075Sobrienchar	mkdirhelp[] =	"make directory on the remote machine";
11890075Sobrienchar	mlshelp[] =	"list contents of multiple remote directories";
11990075Sobrienchar	mlsdhelp[] =	"list contents of remote directory in a machine "
12090075Sobrien			"parsable form";
121132718Skanchar	mlsthelp[] =	"list remote path in a machine parsable form";
122132718Skanchar	modehelp[] =	"set file transfer mode";
12390075Sobrienchar	modtimehelp[] = "show last modification time of remote file";
12490075Sobrienchar	mputhelp[] =	"send multiple files";
12590075Sobrienchar	newerhelp[] =	"get file if remote file is newer than local file ";
12690075Sobrienchar	nmaphelp[] =	"set templates for default file name mapping";
127258428Spfgchar	ntranshelp[] =	"set translation table for default file name mapping";
12890075Sobrienchar	optshelp[] =	"show or set options for remote commands";
12990075Sobrienchar	pagehelp[] =	"view a remote file through your pager";
13090075Sobrienchar	passivehelp[] =	"toggle use of passive transfer mode";
13190075Sobrienchar	plshelp[] =	"list contents of remote path through your pager";
13290075Sobrienchar	pmlsdhelp[] =	"list contents of remote directory in a machine "
13390075Sobrien			"parsable form through your pager";
134258428Spfgchar	porthelp[] =	"toggle use of PORT/LPRT cmd for each data connection";
13590075Sobrienchar	preservehelp[] ="toggle preservation of modification time of "
13690075Sobrien			"retrieved files";
13790075Sobrienchar	progresshelp[] ="toggle transfer progress meter";
13890075Sobrienchar	prompthelp[] =	"force interactive prompting on multiple commands";
13990075Sobrienchar	proxyhelp[] =	"issue command on alternate connection";
14090075Sobrienchar	pwdhelp[] =	"print working directory on remote machine";
14190075Sobrienchar	quithelp[] =	"terminate ftp session and exit";
14290075Sobrienchar	quotehelp[] =	"send arbitrary ftp command";
14390075Sobrienchar	ratehelp[] =	"set transfer rate limit (in bytes/second)";
14490075Sobrienchar	receivehelp[] =	"receive file";
14590075Sobrienchar	regethelp[] =	"get file restarting at end of local file";
14690075Sobrienchar	remotehelp[] =	"get help from remote server";
14790075Sobrienchar	renamehelp[] =	"rename file";
14890075Sobrienchar	resethelp[] =	"clear queued command replies";
14990075Sobrienchar	restarthelp[]=	"restart file transfer at bytecount";
15090075Sobrienchar	rmdirhelp[] =	"remove directory on the remote machine";
15190075Sobrienchar	rmtstatushelp[]="show status of remote machine";
15290075Sobrienchar	runiquehelp[] = "toggle store unique for local files";
15390075Sobrienchar	sendhelp[] =	"send one file";
15490075Sobrienchar	sethelp[] =	"set or display options";
15590075Sobrienchar	shellhelp[] =	"escape to the shell";
15690075Sobrienchar	sitehelp[] =	"send site specific command to remote server\n"
15790075Sobrien			"\t\tTry \"rhelp site\" or \"site help\" "
15890075Sobrien			"for more information";
15990075Sobrienchar	sizecmdhelp[] = "show size of remote file";
16090075Sobrienchar	statushelp[] =	"show current status";
16190075Sobrienchar	structhelp[] =	"set file transfer structure";
162132718Skanchar	suniquehelp[] = "toggle store unique on remote machine";
16390075Sobrienchar	systemhelp[] =  "show remote system type";
16490075Sobrienchar	tenexhelp[] =	"set tenex file transfer type";
165132718Skanchar	tracehelp[] =	"toggle packet tracing";
16690075Sobrienchar	typehelp[] =	"set file transfer type";
16790075Sobrienchar	umaskhelp[] =	"get (set) umask on remote side";
16890075Sobrienchar	unsethelp[] =	"unset an option";
169132718Skanchar	usagehelp[] =	"show command usage";
17090075Sobrienchar	userhelp[] =	"send new user information";
17190075Sobrienchar	verbosehelp[] =	"toggle verbose mode";
17290075Sobrienchar	xferbufhelp[] =	"set socket send/receive buffer size";
173169689Skan
174169689Skan#ifdef NO_EDITCOMPLETE
175169689Skan#define	CMPL(x)
176169689Skan#define	CMPL0
177169689Skan#else  /* !NO_EDITCOMPLETE */
178169689Skan#define	CMPL(x)	#x,
17990075Sobrien#define	CMPL0	"",
18090075Sobrien#endif /* !NO_EDITCOMPLETE */
181132718Skan
182132718Skanstruct cmd cmdtab[] = {
183132718Skan	{ "!",		shellhelp,	0, 0, 0, CMPL0		shell },
184132718Skan	{ "$",		domachelp,	1, 0, 0, CMPL0		domacro },
185132718Skan	{ "account",	accounthelp,	0, 1, 1, CMPL0		account},
186132718Skan	{ "append",	appendhelp,	1, 1, 1, CMPL(lr)	put },
187132718Skan	{ "ascii",	asciihelp,	0, 1, 1, CMPL0		setascii },
188132718Skan	{ "bell",	beephelp,	0, 0, 0, CMPL0		setbell },
189132718Skan	{ "binary",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
190132718Skan	{ "bye",	quithelp,	0, 0, 0, CMPL0		quit },
191132718Skan	{ "case",	casehelp,	0, 0, 1, CMPL0		setcase },
192132718Skan	{ "cd",		cdhelp,		0, 1, 1, CMPL(r)	cd },
193132718Skan	{ "cdup",	cduphelp,	0, 1, 1, CMPL0		cdup },
194132718Skan	{ "chmod",	chmodhelp,	0, 1, 1, CMPL(nr)	do_chmod },
195132718Skan	{ "close",	disconhelp,	0, 1, 1, CMPL0		disconnect },
196132718Skan	{ "cr",		crhelp,		0, 0, 0, CMPL0		setcr },
19790075Sobrien	{ "debug",	debughelp,	0, 0, 0, CMPL0		setdebug },
19890075Sobrien	{ "delete",	deletehelp,	0, 1, 1, CMPL(r)	delete },
19990075Sobrien	{ "dir",	lshelp,		1, 1, 1, CMPL(rl)	ls },
20090075Sobrien	{ "disconnect",	disconhelp,	0, 1, 1, CMPL0		disconnect },
20190075Sobrien	{ "edit",	edithelp,	0, 0, 0, CMPL0		setedit },
20290075Sobrien	{ "epsv4",	epsv4help,	0, 0, 0, CMPL0		setepsv4 },
20390075Sobrien	{ "exit",	quithelp,	0, 0, 0, CMPL0		quit },
20490075Sobrien	{ "features",	feathelp,	0, 1, 1, CMPL0		feat },
20590075Sobrien	{ "fget",	fgethelp,	1, 1, 1, CMPL(l)	fget },
20690075Sobrien	{ "form",	formhelp,	0, 1, 1, CMPL0		setform },
20790075Sobrien	{ "ftp",	connecthelp,	0, 0, 1, CMPL0		setpeer },
20890075Sobrien	{ "gate",	gatehelp,	0, 0, 0, CMPL0		setgate },
20990075Sobrien	{ "get",	receivehelp,	1, 1, 1, CMPL(rl)	get },
210132718Skan	{ "glob",	globhelp,	0, 0, 0, CMPL0		setglob },
211132718Skan	{ "hash",	hashhelp,	0, 0, 0, CMPL0		sethash },
212132718Skan	{ "help",	helphelp,	0, 0, 1, CMPL(C)	help },
213132718Skan	{ "idle",	idlehelp,	0, 1, 1, CMPL0		idlecmd },
214132718Skan	{ "image",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
215132718Skan	{ "lcd",	lcdhelp,	0, 0, 0, CMPL(l)	lcd },
21690075Sobrien	{ "less",	pagehelp,	1, 1, 1, CMPL(r)	page },
217132718Skan	{ "lpage",	lpagehelp,	0, 0, 0, CMPL(l)	lpage },
218132718Skan	{ "lpwd",	lpwdhelp,	0, 0, 0, CMPL0		lpwd },
219132718Skan	{ "ls",		lshelp,		1, 1, 1, CMPL(rl)	ls },
220132718Skan	{ "macdef",	macdefhelp,	0, 0, 0, CMPL0		macdef },
221132718Skan	{ "mdelete",	mdeletehelp,	1, 1, 1, CMPL(R)	mdelete },
222132718Skan	{ "mdir",	mlshelp,	1, 1, 1, CMPL(R)	mls },
223146895Skan	{ "mget",	mgethelp,	1, 1, 1, CMPL(R)	mget },
224132718Skan	{ "mkdir",	mkdirhelp,	0, 1, 1, CMPL(r)	makedir },
22590075Sobrien	{ "mls",	mlshelp,	1, 1, 1, CMPL(R)	mls },
226132718Skan	{ "mlsd",	mlsdhelp,	1, 1, 1, CMPL(r)	ls },
22790075Sobrien	{ "mlst",	mlsthelp,	1, 1, 1, CMPL(r)	mlst },
228132718Skan	{ "mode",	modehelp,	0, 1, 1, CMPL0		setftmode },
229132718Skan	{ "modtime",	modtimehelp,	0, 1, 1, CMPL(r)	modtime },
230132718Skan	{ "more",	pagehelp,	1, 1, 1, CMPL(r)	page },
231132718Skan	{ "mput",	mputhelp,	1, 1, 1, CMPL(L)	mput },
232132718Skan	{ "mreget",	mregethelp,	1, 1, 1, CMPL(R)	mget },
23390075Sobrien	{ "msend",	mputhelp,	1, 1, 1, CMPL(L)	mput },
234132718Skan	{ "newer",	newerhelp,	1, 1, 1, CMPL(r)	newer },
235132718Skan	{ "nlist",	lshelp,		1, 1, 1, CMPL(rl)	ls },
236132718Skan	{ "nmap",	nmaphelp,	0, 0, 1, CMPL0		setnmap },
237132718Skan	{ "ntrans",	ntranshelp,	0, 0, 1, CMPL0		setntrans },
238132718Skan	{ "open",	connecthelp,	0, 0, 1, CMPL0		setpeer },
23990075Sobrien	{ "page",	pagehelp,	1, 1, 1, CMPL(r)	page },
240132718Skan	{ "passive",	passivehelp,	0, 0, 0, CMPL0		setpassive },
241132718Skan	{ "pdir",	plshelp,	1, 1, 1, CMPL(r)	ls },
242132718Skan	{ "pls",	plshelp,	1, 1, 1, CMPL(r)	ls },
243132718Skan	{ "pmlsd",	pmlsdhelp,	1, 1, 1, CMPL(r)	ls },
244132718Skan	{ "preserve",	preservehelp,	0, 0, 0, CMPL0		setpreserve },
24590075Sobrien	{ "progress",	progresshelp,	0, 0, 0, CMPL0		setprogress },
24690075Sobrien	{ "prompt",	prompthelp,	0, 0, 0, CMPL0		setprompt },
247132718Skan	{ "proxy",	proxyhelp,	0, 0, 1, CMPL(c)	doproxy },
24890075Sobrien	{ "put",	sendhelp,	1, 1, 1, CMPL(lr)	put },
24990075Sobrien	{ "pwd",	pwdhelp,	0, 1, 1, CMPL0		pwd },
25090075Sobrien	{ "quit",	quithelp,	0, 0, 0, CMPL0		quit },
25190075Sobrien	{ "quote",	quotehelp,	1, 1, 1, CMPL0		quote },
25290075Sobrien	{ "rate",	ratehelp,	0, 0, 0, CMPL0		setrate },
253132718Skan	{ "rcvbuf",	xferbufhelp,	0, 0, 0, CMPL0		setxferbuf },
254132718Skan	{ "recv",	receivehelp,	1, 1, 1, CMPL(rl)	get },
255132718Skan	{ "reget",	regethelp,	1, 1, 1, CMPL(rl)	reget },
256132718Skan	{ "remopts",	optshelp,	0, 1, 1, CMPL0		opts },
257132718Skan	{ "rename",	renamehelp,	0, 1, 1, CMPL(rr)	renamefile },
258169689Skan	{ "reset",	resethelp,	0, 1, 1, CMPL0		reset },
259169689Skan	{ "restart",	restarthelp,	1, 1, 1, CMPL0		restart },
260169689Skan	{ "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