Home | History | Annotate | Line # | Download | only in ftp
cmdtab.c revision 1.33
      1 /*	$NetBSD: cmdtab.c,v 1.33 1999/11/11 02:53:03 lukem Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996-1999 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.33 1999/11/11 02:53:03 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	mkdirhelp[] =	"make directory on the remote machine";
    120 char	mlshelp[] =	"list contents of multiple remote directories";
    121 char	modehelp[] =	"set file transfer mode";
    122 char	modtimehelp[] = "show last modification time of remote file";
    123 char	mputhelp[] =	"send multiple files";
    124 char	newerhelp[] =	"get file if remote file is newer than local file ";
    125 char	nmaphelp[] =	"set templates for default file name mapping";
    126 char	ntranshelp[] =	"set translation table for default file name mapping";
    127 char	pagehelp[] =	"view a remote file through your pager";
    128 char	passivehelp[] =	"enter passive transfer mode";
    129 char	plshelp[] =	"list contents of remote directory through your pager";
    130 char	porthelp[] =	"toggle use of PORT/LPRT cmd for each data connection";
    131 char	preservehelp[] ="toggle preservation of modification time of "
    132 			"retrieved files";
    133 char	progresshelp[] ="toggle transfer progress meter";
    134 char	prompthelp[] =	"force interactive prompting on multiple commands";
    135 char	proxyhelp[] =	"issue command on alternate connection";
    136 char	pwdhelp[] =	"print working directory on remote machine";
    137 char	quithelp[] =	"terminate ftp session and exit";
    138 char	quotehelp[] =	"send arbitrary ftp command";
    139 char	ratehelp[] =	"set transfer rate limit (in bytes/second)";
    140 char	receivehelp[] =	"receive file";
    141 char	regethelp[] =	"get file restarting at end of local file";
    142 char	remotehelp[] =	"get help from remote server";
    143 char	renamehelp[] =	"rename file";
    144 char	resethelp[] =	"clear queued command replies";
    145 char	restarthelp[]=	"restart file transfer at bytecount";
    146 char	rmdirhelp[] =	"remove directory on the remote machine";
    147 char	rmtstatushelp[]="show status of remote machine";
    148 char	runiquehelp[] = "toggle store unique for local files";
    149 char	sendhelp[] =	"send one file";
    150 char	sethelp[] =	"set or display options";
    151 char	shellhelp[] =	"escape to the shell";
    152 char	sitehelp[] =	"send site specific command to remote server\n"
    153 			"\t\tTry \"rhelp site\" or \"site help\" "
    154 			"for more information";
    155 char	sizecmdhelp[] = "show size of remote file";
    156 char	statushelp[] =	"show current status";
    157 char	structhelp[] =	"set file transfer structure";
    158 char	suniquehelp[] = "toggle store unique on remote machine";
    159 char	systemhelp[] =  "show remote system type";
    160 char	tenexhelp[] =	"set tenex file transfer type";
    161 char	tracehelp[] =	"toggle packet tracing";
    162 char	typehelp[] =	"set file transfer type";
    163 char	umaskhelp[] =	"get (set) umask on remote side";
    164 char	unsethelp[] =	"unset an option";
    165 char	usagehelp[] =	"show command usage";
    166 char	userhelp[] =	"send new user information";
    167 char	verbosehelp[] =	"toggle verbose mode";
    168 char	xferbufhelp[] =	"set socket send/receive buffer size";
    169 
    170 #ifdef NO_EDITCOMPLETE
    171 #define	CMPL(x)
    172 #define	CMPL0
    173 #else  /* !NO_EDITCOMPLETE */
    174 #define	CMPL(x)	__STRING(x),
    175 #define	CMPL0	"",
    176 #endif /* !NO_EDITCOMPLETE */
    177 
    178 struct cmd cmdtab[] = {
    179 	{ "!",		shellhelp,	0, 0, 0, CMPL0		shell },
    180 	{ "$",		domachelp,	1, 0, 0, CMPL0		domacro },
    181 	{ "account",	accounthelp,	0, 1, 1, CMPL0		account},
    182 	{ "append",	appendhelp,	1, 1, 1, CMPL(lr)	put },
    183 	{ "ascii",	asciihelp,	0, 1, 1, CMPL0		setascii },
    184 	{ "bell",	beephelp,	0, 0, 0, CMPL0		setbell },
    185 	{ "binary",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
    186 	{ "bye",	quithelp,	0, 0, 0, CMPL0		quit },
    187 	{ "case",	casehelp,	0, 0, 1, CMPL0		setcase },
    188 	{ "cd",		cdhelp,		0, 1, 1, CMPL(r)	cd },
    189 	{ "cdup",	cduphelp,	0, 1, 1, CMPL0		cdup },
    190 	{ "chmod",	chmodhelp,	0, 1, 1, CMPL(nr)	do_chmod },
    191 	{ "close",	disconhelp,	0, 1, 1, CMPL0		disconnect },
    192 	{ "cr",		crhelp,		0, 0, 0, CMPL0		setcr },
    193 	{ "debug",	debughelp,	0, 0, 0, CMPL0		setdebug },
    194 	{ "delete",	deletehelp,	0, 1, 1, CMPL(r)	delete },
    195 	{ "dir",	lshelp,		1, 1, 1, CMPL(rl)	ls },
    196 	{ "disconnect",	disconhelp,	0, 1, 1, CMPL0		disconnect },
    197 	{ "edit",	edithelp,	0, 0, 0, CMPL0		setedit },
    198 	{ "epsv4",	epsv4help,	0, 0, 0, CMPL0		setepsv4 },
    199 	{ "exit",	quithelp,	0, 0, 0, CMPL0		quit },
    200 	{ "form",	formhelp,	0, 1, 1, CMPL0		setform },
    201 	{ "ftp",	connecthelp,	0, 0, 1, CMPL0		setpeer },
    202 	{ "gate",	gatehelp,	0, 0, 0, CMPL0		setgate },
    203 	{ "get",	receivehelp,	1, 1, 1, CMPL(rl)	get },
    204 	{ "glob",	globhelp,	0, 0, 0, CMPL0		setglob },
    205 	{ "hash",	hashhelp,	0, 0, 0, CMPL0		sethash },
    206 	{ "help",	helphelp,	0, 0, 1, CMPL(C)	help },
    207 	{ "idle",	idlehelp,	0, 1, 1, CMPL0		idlecmd },
    208 	{ "image",	binaryhelp,	0, 1, 1, CMPL0		setbinary },
    209 	{ "lcd",	lcdhelp,	0, 0, 0, CMPL(l)	lcd },
    210 	{ "less",	pagehelp,	1, 1, 1, CMPL(r)	page },
    211 	{ "lpage",	lpagehelp,	0, 0, 0, CMPL(l)	lpage },
    212 	{ "lpwd",	lpwdhelp,	0, 0, 0, CMPL0		lpwd },
    213 	{ "ls",		lshelp,		1, 1, 1, CMPL(rl)	ls },
    214 	{ "macdef",	macdefhelp,	0, 0, 0, CMPL0		macdef },
    215 	{ "mdelete",	mdeletehelp,	1, 1, 1, CMPL(R)	mdelete },
    216 	{ "mdir",	mdirhelp,	1, 1, 1, CMPL(R)	mls },
    217 	{ "mget",	mgethelp,	1, 1, 1, CMPL(R)	mget },
    218 	{ "mkdir",	mkdirhelp,	0, 1, 1, CMPL(r)	makedir },
    219 	{ "mls",	mlshelp,	1, 1, 1, CMPL(R)	mls },
    220 	{ "mode",	modehelp,	0, 1, 1, CMPL0		setftmode },
    221 	{ "modtime",	modtimehelp,	0, 1, 1, CMPL(r)	modtime },
    222 	{ "more",	pagehelp,	1, 1, 1, CMPL(r)	page },
    223 	{ "mput",	mputhelp,	1, 1, 1, CMPL(L)	mput },
    224 	{ "msend",	mputhelp,	1, 1, 1, CMPL(L)	mput },
    225 	{ "newer",	newerhelp,	1, 1, 1, CMPL(r)	newer },
    226 	{ "nlist",	lshelp,		1, 1, 1, CMPL(rl)	ls },
    227 	{ "nmap",	nmaphelp,	0, 0, 1, CMPL0		setnmap },
    228 	{ "ntrans",	ntranshelp,	0, 0, 1, CMPL0		setntrans },
    229 	{ "open",	connecthelp,	0, 0, 1, CMPL0		setpeer },
    230 	{ "page",	pagehelp,	1, 1, 1, CMPL(r)	page },
    231 	{ "passive",	passivehelp,	0, 0, 0, CMPL0		setpassive },
    232 	{ "pdir",	plshelp,	1, 1, 1, CMPL(rl)	ls },
    233 	{ "pls",	plshelp,	1, 1, 1, CMPL(rl)	ls },
    234 	{ "preserve",	preservehelp,	0, 0, 0, CMPL0		setpreserve },
    235 	{ "progress",	progresshelp,	0, 0, 0, CMPL0		setprogress },
    236 	{ "prompt",	prompthelp,	0, 0, 0, CMPL0		setprompt },
    237 	{ "proxy",	proxyhelp,	0, 0, 1, CMPL(c)	doproxy },
    238 	{ "put",	sendhelp,	1, 1, 1, CMPL(lr)	put },
    239 	{ "pwd",	pwdhelp,	0, 1, 1, CMPL0		pwd },
    240 	{ "quit",	quithelp,	0, 0, 0, CMPL0		quit },
    241 	{ "quote",	quotehelp,	1, 1, 1, CMPL0		quote },
    242 	{ "rate",	ratehelp,	0, 0, 0, CMPL0		setrate },
    243 	{ "rcvbuf",	xferbufhelp,	0, 0, 0, CMPL0		setxferbuf },
    244 	{ "recv",	receivehelp,	1, 1, 1, CMPL(rl)	get },
    245 	{ "reget",	regethelp,	1, 1, 1, CMPL(rl)	reget },
    246 	{ "rename",	renamehelp,	0, 1, 1, CMPL(rr)	renamefile },
    247 	{ "reset",	resethelp,	0, 1, 1, CMPL0		reset },
    248 	{ "restart",	restarthelp,	1, 1, 1, CMPL0		restart },
    249 	{ "rhelp",	remotehelp,	0, 1, 1, CMPL0		rmthelp },
    250 	{ "rmdir",	rmdirhelp,	0, 1, 1, CMPL(r)	removedir },
    251 	{ "rstatus",	rmtstatushelp,	0, 1, 1, CMPL(r)	rmtstatus },
    252 	{ "runique",	runiquehelp,	0, 0, 1, CMPL0		setrunique },
    253 	{ "send",	sendhelp,	1, 1, 1, CMPL(lr)	put },
    254 	{ "sendport",	porthelp,	0, 0, 0, CMPL0		setport },
    255 	{ "set",	sethelp,	0, 0, 0, CMPL(o)	setoption },
    256 	{ "site",	sitehelp,	0, 1, 1, CMPL0		site },
    257 	{ "size",	sizecmdhelp,	1, 1, 1, CMPL(r)	sizecmd },
    258 	{ "sndbuf",	xferbufhelp,	0, 0, 0, CMPL0		setxferbuf },
    259 	{ "status",	statushelp,	0, 0, 1, CMPL0		status },
    260 	{ "struct",	structhelp,	0, 1, 1, CMPL0		setstruct },
    261 	{ "sunique",	suniquehelp,	0, 0, 1, CMPL0		setsunique },
    262 	{ "system",	systemhelp,	0, 1, 1, CMPL0		syst },
    263 	{ "tenex",	tenexhelp,	0, 1, 1, CMPL0		settenex },
    264 	{ "throttle",	ratehelp,	0, 0, 0, CMPL0		setrate },
    265 	{ "trace",	tracehelp,	0, 0, 0, CMPL0		settrace },
    266 	{ "type",	typehelp,	0, 1, 1, CMPL0		settype },
    267 	{ "umask",	umaskhelp,	0, 1, 1, CMPL0		do_umask },
    268 	{ "unset",	unsethelp,	0, 0, 0, CMPL(o)	unsetoption },
    269 	{ "usage",	usagehelp,	0, 0, 1, CMPL(C)	help },
    270 	{ "user",	userhelp,	0, 1, 1, CMPL0		user },
    271 	{ "verbose",	verbosehelp,	0, 0, 0, CMPL0		setverbose },
    272 	{ "xferbuf",	xferbufhelp,	0, 0, 0, CMPL0		setxferbuf },
    273 	{ "?",		helphelp,	0, 0, 1, CMPL(C)	help },
    274 	{ 0 },
    275 };
    276 
    277 struct option optiontab[] = {
    278 	{ "anonpass",	NULL },
    279 	{ "ftp_proxy",	NULL },
    280 	{ "http_proxy",	NULL },
    281 	{ "no_proxy",	NULL },
    282 	{ "pager",	NULL },
    283 	{ "prompt",	NULL },
    284 	{ 0 },
    285 };
    286