xref: /netbsd-src/usr.bin/ftp/cmdtab.c (revision 1394f01b4a9e99092957ca5d824d67219565d9b5)
1 /*	$NetBSD: cmdtab.c,v 1.15 1997/04/05 03:27:33 lukem Exp $	*/
2 
3 /*
4  * Copyright (c) 1985, 1989, 1993, 1994
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)cmdtab.c	8.4 (Berkeley) 10/9/94";
39 #else
40 static char rcsid[] = "$NetBSD: cmdtab.c,v 1.15 1997/04/05 03:27:33 lukem Exp $";
41 #endif
42 #endif /* not lint */
43 
44 #include <stdio.h>
45 #include "ftp_var.h"
46 
47 /*
48  * User FTP -- Command Tables.
49  */
50 
51 char	accounthelp[] =	"send account command to remote server";
52 char	appendhelp[] =	"append to a file";
53 char	asciihelp[] =	"set ascii transfer type";
54 char	beephelp[] =	"beep when command completed";
55 char	binaryhelp[] =	"set binary transfer type";
56 char	casehelp[] =	"toggle mget upper/lower case id mapping";
57 char	cdhelp[] =	"change remote working directory";
58 char	cduphelp[] =	"change remote working directory to parent directory";
59 char	chmodhelp[] =	"change file permissions of remote file";
60 char	connecthelp[] =	"connect to remote ftp server";
61 char	crhelp[] =	"toggle carriage return stripping on ascii gets";
62 char	debughelp[] =	"toggle/set debugging mode";
63 char	deletehelp[] =	"delete remote file";
64 char	dirhelp[] =	"list contents of remote directory";
65 char	disconhelp[] =	"terminate ftp session";
66 char	domachelp[] =	"execute macro";
67 #ifndef SMALL
68 char	edithelp[] =	"toggle command line editing";
69 #endif /* !SMALL */
70 char	formhelp[] =	"set file transfer format";
71 char	globhelp[] =	"toggle metacharacter expansion of local file names";
72 char	hashhelp[] =	"toggle printing `#' marks; specify number to set size";
73 char	helphelp[] =	"print local help information";
74 char	idlehelp[] =	"get (set) idle timer on remote side";
75 char	lcdhelp[] =	"change local working directory";
76 char	lpwdhelp[] =	"print local working directory";
77 char	lshelp[] =	"list contents of remote directory";
78 char	macdefhelp[] =  "define a macro";
79 char	mdeletehelp[] =	"delete multiple files";
80 char	mdirhelp[] =	"list contents of multiple remote directories";
81 char	mgethelp[] =	"get multiple files";
82 char	mkdirhelp[] =	"make directory on the remote machine";
83 char	mlshelp[] =	"list contents of multiple remote directories";
84 char	modehelp[] =	"set file transfer mode";
85 char	modtimehelp[] = "show last modification time of remote file";
86 char	mputhelp[] =	"send multiple files";
87 char	newerhelp[] =	"get file if remote file is newer than local file ";
88 char	nlisthelp[] =	"nlist contents of remote directory";
89 char	nmaphelp[] =	"set templates for default file name mapping";
90 char	ntranshelp[] =	"set translation table for default file name mapping";
91 char	pagehelp[] =	"view a remote file through your pager";
92 char	passivehelp[] =	"enter passive transfer mode";
93 char	porthelp[] =	"toggle use of PORT cmd for each data connection";
94 char	preservehelp[] ="toggle preservation of modification time of "
95 			"retreived files";
96 char	progresshelp[] ="toggle transfer progress meter";
97 char	prompthelp[] =	"force interactive prompting on multiple commands";
98 char	proxyhelp[] =	"issue command on alternate connection";
99 char	pwdhelp[] =	"print working directory on remote machine";
100 char	quithelp[] =	"terminate ftp session and exit";
101 char	quotehelp[] =	"send arbitrary ftp command";
102 char	receivehelp[] =	"receive file";
103 char	regethelp[] =	"get file restarting at end of local file";
104 char	remotehelp[] =	"get help from remote server";
105 char	renamehelp[] =	"rename file";
106 char	resethelp[] =	"clear queued command replies";
107 char	restarthelp[]=	"restart file transfer at bytecount";
108 char	rmdirhelp[] =	"remove directory on the remote machine";
109 char	rmtstatushelp[]="show status of remote machine";
110 char	runiquehelp[] = "toggle store unique for local files";
111 char	sendhelp[] =	"send one file";
112 char	shellhelp[] =	"escape to the shell";
113 char	sitehelp[] =	"send site specific command to remote server\n"
114 			"\t\tTry \"rhelp site\" or \"site help\" "
115 			"for more information";
116 char	sizecmdhelp[] = "show size of remote file";
117 char	statushelp[] =	"show current status";
118 char	structhelp[] =	"set file transfer structure";
119 char	suniquehelp[] = "toggle store unique on remote machine";
120 char	systemhelp[] =  "show remote system type";
121 char	tenexhelp[] =	"set tenex file transfer type";
122 char	tracehelp[] =	"toggle packet tracing";
123 char	typehelp[] =	"set file transfer type";
124 char	umaskhelp[] =	"get (set) umask on remote side";
125 char	userhelp[] =	"send new user information";
126 char	verbosehelp[] =	"toggle verbose mode";
127 
128 #ifdef SMALL
129 #define CMPL(x)
130 #define CMPL0
131 #else  /* !SMALL */
132 #define CMPL(x)	__STRING(x),
133 #define CMPL0	"",
134 #endif /* !SMALL */
135 
136 struct cmd cmdtab[] = {
137 	{ "!",		shellhelp,	0, 0, 0, CMPL0		shell },
138 	{ "$",		domachelp,	1, 0, 0, CMPL0		domacro },
139 	{ "account",	accounthelp,	0, 1, 1, CMPL0		account},
140 	{ "append",	appendhelp,	1, 1, 1, CMPL(lr)	put },
141 	{ "ascii",	asciihelp,	0, 1, 1, CMPL0		setascii },
142 	{ "bell",	beephelp,	0, 0, 0, CMPL0		setbell },
143 	{ "binary",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
144 	{ "bye",	quithelp,	0, 0, 0, CMPL0		quit },
145 	{ "case",	casehelp,	0, 0, 1, CMPL0		setcase },
146 	{ "cd",		cdhelp,		0, 1, 1, CMPL(r)	cd },
147 	{ "cdup",	cduphelp,	0, 1, 1, CMPL0		cdup },
148 	{ "chmod",	chmodhelp,	0, 1, 1, CMPL(nr)	do_chmod },
149 	{ "close",	disconhelp,	0, 1, 1, CMPL0		disconnect },
150 	{ "cr",		crhelp,		0, 0, 0, CMPL0		setcr },
151 	{ "debug",	debughelp,	0, 0, 0, CMPL0		setdebug },
152 	{ "delete",	deletehelp,	0, 1, 1, CMPL(r)	delete },
153 	{ "dir",	dirhelp,	1, 1, 1, CMPL(rl)	ls },
154 	{ "disconnect",	disconhelp,	0, 1, 1, CMPL0		disconnect },
155 #ifndef SMALL
156 	{ "edit",	edithelp,	0, 0, 0, CMPL0		setedit },
157 #endif /* !SMALL */
158 	{ "exit",	quithelp,	0, 0, 0, CMPL0		quit },
159 	{ "form",	formhelp,	0, 1, 1, CMPL0		setform },
160 	{ "ftp",	connecthelp,	0, 0, 1, CMPL0		setpeer },
161 	{ "get",	receivehelp,	1, 1, 1, CMPL(rl)	get },
162 	{ "glob",	globhelp,	0, 0, 0, CMPL0		setglob },
163 	{ "hash",	hashhelp,	0, 0, 0, CMPL0		sethash },
164 	{ "help",	helphelp,	0, 0, 1, CMPL(C)	help },
165 	{ "idle",	idlehelp,	0, 1, 1, CMPL0		idle },
166 	{ "image",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
167 	{ "lcd",	lcdhelp,	0, 0, 0, CMPL(l)	lcd },
168 	{ "less",	pagehelp,	1, 1, 1, CMPL(r)	page },
169 	{ "lpwd",	lpwdhelp,	0, 0, 0, CMPL0		lpwd },
170 	{ "ls",		lshelp,		1, 1, 1, CMPL(rl)	ls },
171 	{ "macdef",	macdefhelp,	0, 0, 0, CMPL0		macdef },
172 	{ "mdelete",	mdeletehelp,	1, 1, 1, CMPL(R)	mdelete },
173 	{ "mdir",	mdirhelp,	1, 1, 1, CMPL(R)	mls },
174 	{ "mget",	mgethelp,	1, 1, 1, CMPL(R)	mget },
175 	{ "mkdir",	mkdirhelp,	0, 1, 1, CMPL(r)	makedir },
176 	{ "mls",	mlshelp,	1, 1, 1, CMPL(R)	mls },
177 	{ "mode",	modehelp,	0, 1, 1, CMPL0		setftmode },
178 	{ "modtime",	modtimehelp,	0, 1, 1, CMPL(r)	modtime },
179 	{ "more",	pagehelp,	1, 1, 1, CMPL(r)	page },
180 	{ "mput",	mputhelp,	1, 1, 1, CMPL(L)	mput },
181 	{ "msend",	mputhelp,	1, 1, 1, CMPL(L)	mput },
182 	{ "newer",	newerhelp,	1, 1, 1, CMPL(r)	newer },
183 	{ "nlist",	nlisthelp,	1, 1, 1, CMPL(rl)	ls },
184 	{ "nmap",	nmaphelp,	0, 0, 1, CMPL0		setnmap },
185 	{ "ntrans",	ntranshelp,	0, 0, 1, CMPL0		setntrans },
186 	{ "open",	connecthelp,	0, 0, 1, CMPL0		setpeer },
187 	{ "page",	pagehelp,	1, 1, 1, CMPL(r)	page },
188 	{ "passive",	passivehelp,	0, 0, 0, CMPL0		setpassive },
189 	{ "preserve",	preservehelp,	0, 0, 0, CMPL0		setpreserve },
190 	{ "progress",	progresshelp,	0, 0, 0, CMPL0		setprogress },
191 	{ "prompt",	prompthelp,	0, 0, 0, CMPL0		setprompt },
192 	{ "proxy",	proxyhelp,	0, 0, 1, CMPL(c)	doproxy },
193 	{ "put",	sendhelp,	1, 1, 1, CMPL(lr)	put },
194 	{ "pwd",	pwdhelp,	0, 1, 1, CMPL0		pwd },
195 	{ "quit",	quithelp,	0, 0, 0, CMPL0		quit },
196 	{ "quote",	quotehelp,	1, 1, 1, CMPL0		quote },
197 	{ "recv",	receivehelp,	1, 1, 1, CMPL(rl)	get },
198 	{ "reget",	regethelp,	1, 1, 1, CMPL(rl)	reget },
199 	{ "rename",	renamehelp,	0, 1, 1, CMPL(rr)	renamefile },
200 	{ "reset",	resethelp,	0, 1, 1, CMPL0		reset },
201 	{ "restart",	restarthelp,	1, 1, 1, CMPL0		restart },
202 	{ "rhelp",	remotehelp,	0, 1, 1, CMPL0		rmthelp },
203 	{ "rmdir",	rmdirhelp,	0, 1, 1, CMPL(r)	removedir },
204 	{ "rstatus",	rmtstatushelp,	0, 1, 1, CMPL(r)	rmtstatus },
205 	{ "runique",	runiquehelp,	0, 0, 1, CMPL0		setrunique },
206 	{ "send",	sendhelp,	1, 1, 1, CMPL(lr)	put },
207 	{ "sendport",	porthelp,	0, 0, 0, CMPL0		setport },
208 	{ "site",	sitehelp,	0, 1, 1, CMPL0		site },
209 	{ "size",	sizecmdhelp,	1, 1, 1, CMPL(r)	sizecmd },
210 	{ "status",	statushelp,	0, 0, 1, CMPL0		status },
211 	{ "struct",	structhelp,	0, 1, 1, CMPL0		setstruct },
212 	{ "sunique",	suniquehelp,	0, 0, 1, CMPL0		setsunique },
213 	{ "system",	systemhelp,	0, 1, 1, CMPL0		syst },
214 	{ "tenex",	tenexhelp,	0, 1, 1, CMPL0		settenex },
215 	{ "trace",	tracehelp,	0, 0, 0, CMPL0		settrace },
216 	{ "type",	typehelp,	0, 1, 1, CMPL0		settype },
217 	{ "umask",	umaskhelp,	0, 1, 1, CMPL0		do_umask },
218 	{ "user",	userhelp,	0, 1, 1, CMPL0		user },
219 	{ "verbose",	verbosehelp,	0, 0, 0, CMPL0		setverbose },
220 	{ "?",		helphelp,	0, 0, 1, CMPL(C)	help },
221 	{ 0 },
222 };
223 
224 int	NCMDS = (sizeof(cmdtab) / sizeof(cmdtab[0])) - 1;
225