Home | History | Annotate | Line # | Download | only in ftp
cmds.c revision 1.123
      1  1.123     lukem /*	$NetBSD: cmds.c,v 1.123 2007/05/24 05:05:18 lukem Exp $	*/
      2   1.39   thorpej 
      3   1.39   thorpej /*-
      4  1.119     lukem  * Copyright (c) 1996-2007 The NetBSD Foundation, Inc.
      5   1.39   thorpej  * All rights reserved.
      6   1.39   thorpej  *
      7   1.39   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.70     lukem  * by Luke Mewburn.
      9   1.70     lukem  *
     10   1.70     lukem  * This code is derived from software contributed to The NetBSD Foundation
     11   1.39   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     12   1.39   thorpej  * NASA Ames Research Center.
     13   1.39   thorpej  *
     14   1.39   thorpej  * Redistribution and use in source and binary forms, with or without
     15   1.39   thorpej  * modification, are permitted provided that the following conditions
     16   1.39   thorpej  * are met:
     17   1.39   thorpej  * 1. Redistributions of source code must retain the above copyright
     18   1.39   thorpej  *    notice, this list of conditions and the following disclaimer.
     19   1.39   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     20   1.39   thorpej  *    notice, this list of conditions and the following disclaimer in the
     21   1.39   thorpej  *    documentation and/or other materials provided with the distribution.
     22   1.39   thorpej  * 3. All advertising materials mentioning features or use of this software
     23   1.39   thorpej  *    must display the following acknowledgement:
     24   1.39   thorpej  *	This product includes software developed by the NetBSD
     25   1.39   thorpej  *	Foundation, Inc. and its contributors.
     26   1.39   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     27   1.39   thorpej  *    contributors may be used to endorse or promote products derived
     28   1.39   thorpej  *    from this software without specific prior written permission.
     29   1.39   thorpej  *
     30   1.39   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     31   1.39   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     32   1.39   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     33   1.39   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     34   1.39   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     35   1.39   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     36   1.39   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     37   1.39   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     38   1.39   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39   1.39   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     40   1.39   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     41   1.39   thorpej  */
     42    1.8       tls 
     43    1.1       cgd /*
     44    1.4       cgd  * Copyright (c) 1985, 1989, 1993, 1994
     45    1.4       cgd  *	The Regents of the University of California.  All rights reserved.
     46    1.1       cgd  *
     47    1.1       cgd  * Redistribution and use in source and binary forms, with or without
     48    1.1       cgd  * modification, are permitted provided that the following conditions
     49    1.1       cgd  * are met:
     50    1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     51    1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     52    1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     53    1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     54    1.1       cgd  *    documentation and/or other materials provided with the distribution.
     55  1.102       agc  * 3. Neither the name of the University nor the names of its contributors
     56    1.1       cgd  *    may be used to endorse or promote products derived from this software
     57    1.1       cgd  *    without specific prior written permission.
     58    1.1       cgd  *
     59    1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60    1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61    1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62    1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63    1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64    1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65    1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66    1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67    1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68    1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69    1.1       cgd  * SUCH DAMAGE.
     70    1.1       cgd  */
     71    1.1       cgd 
     72   1.65     lukem /*
     73   1.65     lukem  * Copyright (C) 1997 and 1998 WIDE Project.
     74   1.65     lukem  * All rights reserved.
     75  1.112     lukem  *
     76   1.65     lukem  * Redistribution and use in source and binary forms, with or without
     77   1.65     lukem  * modification, are permitted provided that the following conditions
     78   1.65     lukem  * are met:
     79   1.65     lukem  * 1. Redistributions of source code must retain the above copyright
     80   1.65     lukem  *    notice, this list of conditions and the following disclaimer.
     81   1.65     lukem  * 2. Redistributions in binary form must reproduce the above copyright
     82   1.65     lukem  *    notice, this list of conditions and the following disclaimer in the
     83   1.65     lukem  *    documentation and/or other materials provided with the distribution.
     84   1.65     lukem  * 3. Neither the name of the project nor the names of its contributors
     85   1.65     lukem  *    may be used to endorse or promote products derived from this software
     86   1.65     lukem  *    without specific prior written permission.
     87  1.112     lukem  *
     88   1.65     lukem  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     89   1.65     lukem  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     90   1.65     lukem  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     91   1.65     lukem  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     92   1.65     lukem  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     93   1.65     lukem  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     94   1.65     lukem  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     95   1.65     lukem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     96   1.65     lukem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     97   1.65     lukem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     98   1.65     lukem  * SUCH DAMAGE.
     99   1.65     lukem  */
    100   1.65     lukem 
    101   1.25     lukem #include <sys/cdefs.h>
    102    1.1       cgd #ifndef lint
    103    1.8       tls #if 0
    104    1.8       tls static char sccsid[] = "@(#)cmds.c	8.6 (Berkeley) 10/9/94";
    105    1.8       tls #else
    106  1.123     lukem __RCSID("$NetBSD: cmds.c,v 1.123 2007/05/24 05:05:18 lukem Exp $");
    107    1.8       tls #endif
    108    1.1       cgd #endif /* not lint */
    109    1.1       cgd 
    110    1.1       cgd /*
    111    1.1       cgd  * FTP User Program -- Command Routines.
    112    1.1       cgd  */
    113   1.16     lukem #include <sys/types.h>
    114   1.16     lukem #include <sys/socket.h>
    115   1.16     lukem #include <sys/stat.h>
    116    1.1       cgd #include <sys/wait.h>
    117    1.1       cgd #include <arpa/ftp.h>
    118    1.1       cgd 
    119    1.4       cgd #include <ctype.h>
    120    1.4       cgd #include <err.h>
    121    1.4       cgd #include <glob.h>
    122   1.42     lukem #include <limits.h>
    123    1.4       cgd #include <netdb.h>
    124   1.67     lukem #include <paths.h>
    125    1.1       cgd #include <stdio.h>
    126    1.4       cgd #include <stdlib.h>
    127    1.4       cgd #include <string.h>
    128   1.35    kleink #include <time.h>
    129    1.4       cgd #include <unistd.h>
    130    1.1       cgd 
    131    1.1       cgd #include "ftp_var.h"
    132   1.81     lukem #include "version.h"
    133    1.1       cgd 
    134  1.121     lukem static struct types {
    135    1.1       cgd 	char	*t_name;
    136    1.1       cgd 	char	*t_mode;
    137    1.1       cgd 	int	t_type;
    138    1.1       cgd 	char	*t_arg;
    139    1.1       cgd } types[] = {
    140    1.1       cgd 	{ "ascii",	"A",	TYPE_A,	0 },
    141    1.1       cgd 	{ "binary",	"I",	TYPE_I,	0 },
    142    1.1       cgd 	{ "image",	"I",	TYPE_I,	0 },
    143    1.1       cgd 	{ "ebcdic",	"E",	TYPE_E,	0 },
    144    1.1       cgd 	{ "tenex",	"L",	TYPE_L,	bytename },
    145    1.4       cgd 	{ NULL }
    146    1.1       cgd };
    147    1.1       cgd 
    148  1.121     lukem static sigjmp_buf	 jabort;
    149   1.74     lukem 
    150   1.85     lukem static int	confirm(const char *, const char *);
    151  1.121     lukem static void	mintr(int);
    152  1.121     lukem static void	mabort(const char *);
    153   1.74     lukem 
    154  1.110  christos static const char *doprocess(char *, size_t, const char *, int, int, int);
    155  1.110  christos static const char *domap(char *, size_t, const char *);
    156  1.110  christos static const char *docase(char *, size_t, const char *);
    157  1.110  christos static const char *dotrans(char *, size_t, const char *);
    158  1.110  christos 
    159  1.121     lukem /*
    160  1.121     lukem  * Confirm if "cmd" is to be performed upon "file".
    161  1.121     lukem  * If "file" is NULL, generate a "Continue with" prompt instead.
    162  1.121     lukem  */
    163   1.74     lukem static int
    164   1.85     lukem confirm(const char *cmd, const char *file)
    165   1.74     lukem {
    166  1.115     lukem 	const char *errormsg;
    167   1.74     lukem 	char line[BUFSIZ];
    168  1.121     lukem 	const char *promptleft, *promptright;
    169   1.74     lukem 
    170   1.74     lukem 	if (!interactive || confirmrest)
    171   1.74     lukem 		return (1);
    172  1.121     lukem 	if (file == NULL) {
    173  1.121     lukem 		promptleft = "Continue with";
    174  1.121     lukem 		promptright = cmd;
    175  1.121     lukem 	} else {
    176  1.121     lukem 		promptleft = cmd;
    177  1.121     lukem 		promptright = file;
    178  1.121     lukem 	}
    179   1.74     lukem 	while (1) {
    180  1.121     lukem 		fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright);
    181   1.74     lukem 		(void)fflush(ttyout);
    182  1.115     lukem 		if (getline(stdin, line, sizeof(line), &errormsg) < 0) {
    183   1.74     lukem 			mflag = 0;
    184  1.121     lukem 			fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd);
    185   1.74     lukem 			return (0);
    186   1.74     lukem 		}
    187  1.108       dsl 		switch (tolower((unsigned char)*line)) {
    188   1.74     lukem 			case 'a':
    189   1.74     lukem 				confirmrest = 1;
    190   1.74     lukem 				fprintf(ttyout,
    191   1.74     lukem 				    "Prompting off for duration of %s.\n", cmd);
    192   1.74     lukem 				break;
    193   1.74     lukem 			case 'p':
    194   1.74     lukem 				interactive = 0;
    195   1.74     lukem 				fputs("Interactive mode: off.\n", ttyout);
    196   1.74     lukem 				break;
    197   1.74     lukem 			case 'q':
    198   1.74     lukem 				mflag = 0;
    199  1.121     lukem 				fprintf(ttyout, "%s aborted.\n", cmd);
    200   1.75     lukem 				/* FALLTHROUGH */
    201   1.75     lukem 			case 'n':
    202   1.74     lukem 				return (0);
    203   1.74     lukem 			case '?':
    204   1.74     lukem 				fprintf(ttyout,
    205   1.76     lukem 				    "  confirmation options:\n"
    206   1.74     lukem 				    "\ta  answer `yes' for the duration of %s\n"
    207   1.74     lukem 				    "\tn  answer `no' for this file\n"
    208   1.74     lukem 				    "\tp  turn off `prompt' mode\n"
    209   1.74     lukem 				    "\tq  stop the current %s\n"
    210   1.74     lukem 				    "\ty  answer `yes' for this file\n"
    211   1.74     lukem 				    "\t?  this help list\n",
    212   1.74     lukem 				    cmd, cmd);
    213   1.75     lukem 				continue;	/* back to while(1) */
    214   1.74     lukem 		}
    215   1.75     lukem 		return (1);
    216   1.74     lukem 	}
    217   1.74     lukem 	/* NOTREACHED */
    218   1.74     lukem }
    219   1.74     lukem 
    220    1.1       cgd /*
    221    1.1       cgd  * Set transfer type.
    222    1.1       cgd  */
    223    1.4       cgd void
    224   1.85     lukem settype(int argc, char *argv[])
    225    1.1       cgd {
    226    1.4       cgd 	struct types *p;
    227    1.1       cgd 	int comret;
    228    1.1       cgd 
    229   1.88     lukem 	if (argc == 0 || argc > 2) {
    230    1.1       cgd 		char *sep;
    231    1.1       cgd 
    232  1.116  christos 		UPRINTF("usage: %s [", argv[0]);
    233    1.1       cgd 		sep = " ";
    234    1.1       cgd 		for (p = types; p->t_name; p++) {
    235   1.37     lukem 			fprintf(ttyout, "%s%s", sep, p->t_name);
    236    1.1       cgd 			sep = " | ";
    237    1.1       cgd 		}
    238   1.37     lukem 		fputs(" ]\n", ttyout);
    239    1.1       cgd 		code = -1;
    240    1.1       cgd 		return;
    241    1.1       cgd 	}
    242    1.1       cgd 	if (argc < 2) {
    243   1.37     lukem 		fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
    244    1.1       cgd 		code = 0;
    245    1.1       cgd 		return;
    246    1.1       cgd 	}
    247    1.1       cgd 	for (p = types; p->t_name; p++)
    248    1.1       cgd 		if (strcmp(argv[1], p->t_name) == 0)
    249    1.1       cgd 			break;
    250    1.1       cgd 	if (p->t_name == 0) {
    251   1.37     lukem 		fprintf(ttyout, "%s: unknown mode.\n", argv[1]);
    252    1.1       cgd 		code = -1;
    253    1.1       cgd 		return;
    254    1.1       cgd 	}
    255    1.1       cgd 	if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
    256   1.19     lukem 		comret = command("TYPE %s %s", p->t_mode, p->t_arg);
    257    1.1       cgd 	else
    258    1.1       cgd 		comret = command("TYPE %s", p->t_mode);
    259    1.1       cgd 	if (comret == COMPLETE) {
    260   1.63     lukem 		(void)strlcpy(typename, p->t_name, sizeof(typename));
    261    1.1       cgd 		curtype = type = p->t_type;
    262    1.1       cgd 	}
    263    1.1       cgd }
    264    1.1       cgd 
    265    1.1       cgd /*
    266    1.1       cgd  * Internal form of settype; changes current type in use with server
    267    1.1       cgd  * without changing our notion of the type for data transfers.
    268    1.1       cgd  * Used to change to and from ascii for listings.
    269    1.1       cgd  */
    270    1.4       cgd void
    271   1.85     lukem changetype(int newtype, int show)
    272    1.1       cgd {
    273    1.4       cgd 	struct types *p;
    274    1.1       cgd 	int comret, oldverbose = verbose;
    275    1.1       cgd 
    276    1.1       cgd 	if (newtype == 0)
    277    1.1       cgd 		newtype = TYPE_I;
    278    1.1       cgd 	if (newtype == curtype)
    279    1.1       cgd 		return;
    280  1.118  christos 	if (ftp_debug == 0 && show == 0)
    281    1.1       cgd 		verbose = 0;
    282    1.1       cgd 	for (p = types; p->t_name; p++)
    283    1.1       cgd 		if (newtype == p->t_type)
    284    1.1       cgd 			break;
    285    1.1       cgd 	if (p->t_name == 0) {
    286  1.120     lukem 		errx(1, "changetype: unknown type %d", newtype);
    287    1.1       cgd 	}
    288    1.1       cgd 	if (newtype == TYPE_L && bytename[0] != '\0')
    289    1.1       cgd 		comret = command("TYPE %s %s", p->t_mode, bytename);
    290    1.1       cgd 	else
    291    1.1       cgd 		comret = command("TYPE %s", p->t_mode);
    292    1.1       cgd 	if (comret == COMPLETE)
    293    1.1       cgd 		curtype = newtype;
    294    1.1       cgd 	verbose = oldverbose;
    295    1.1       cgd }
    296    1.1       cgd 
    297    1.1       cgd char *stype[] = {
    298    1.1       cgd 	"type",
    299    1.1       cgd 	"",
    300    1.1       cgd 	0
    301    1.1       cgd };
    302    1.1       cgd 
    303    1.1       cgd /*
    304    1.1       cgd  * Set binary transfer type.
    305    1.1       cgd  */
    306    1.1       cgd /*VARARGS*/
    307    1.4       cgd void
    308   1.85     lukem setbinary(int argc, char *argv[])
    309    1.1       cgd {
    310    1.4       cgd 
    311   1.88     lukem 	if (argc == 0) {
    312  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    313   1.76     lukem 		code = -1;
    314   1.76     lukem 		return;
    315   1.76     lukem 	}
    316    1.1       cgd 	stype[1] = "binary";
    317    1.1       cgd 	settype(2, stype);
    318    1.1       cgd }
    319    1.1       cgd 
    320    1.1       cgd /*
    321    1.1       cgd  * Set ascii transfer type.
    322    1.1       cgd  */
    323    1.1       cgd /*VARARGS*/
    324    1.4       cgd void
    325   1.85     lukem setascii(int argc, char *argv[])
    326    1.1       cgd {
    327    1.4       cgd 
    328   1.88     lukem 	if (argc == 0) {
    329  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    330   1.76     lukem 		code = -1;
    331   1.76     lukem 		return;
    332   1.76     lukem 	}
    333    1.1       cgd 	stype[1] = "ascii";
    334    1.1       cgd 	settype(2, stype);
    335    1.1       cgd }
    336    1.1       cgd 
    337    1.1       cgd /*
    338    1.1       cgd  * Set tenex transfer type.
    339    1.1       cgd  */
    340    1.1       cgd /*VARARGS*/
    341    1.4       cgd void
    342   1.85     lukem settenex(int argc, char *argv[])
    343    1.1       cgd {
    344    1.4       cgd 
    345   1.88     lukem 	if (argc == 0) {
    346  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    347   1.76     lukem 		code = -1;
    348   1.76     lukem 		return;
    349   1.76     lukem 	}
    350    1.1       cgd 	stype[1] = "tenex";
    351    1.1       cgd 	settype(2, stype);
    352    1.1       cgd }
    353    1.1       cgd 
    354    1.1       cgd /*
    355    1.1       cgd  * Set file transfer mode.
    356    1.1       cgd  */
    357    1.1       cgd /*ARGSUSED*/
    358    1.4       cgd void
    359   1.85     lukem setftmode(int argc, char *argv[])
    360    1.1       cgd {
    361    1.1       cgd 
    362   1.88     lukem 	if (argc != 2) {
    363  1.116  christos 		UPRINTF("usage: %s mode-name\n", argv[0]);
    364   1.76     lukem 		code = -1;
    365   1.76     lukem 		return;
    366   1.76     lukem 	}
    367   1.37     lukem 	fprintf(ttyout, "We only support %s mode, sorry.\n", modename);
    368    1.1       cgd 	code = -1;
    369    1.1       cgd }
    370    1.1       cgd 
    371    1.1       cgd /*
    372    1.1       cgd  * Set file transfer format.
    373    1.1       cgd  */
    374    1.1       cgd /*ARGSUSED*/
    375    1.4       cgd void
    376   1.85     lukem setform(int argc, char *argv[])
    377    1.1       cgd {
    378    1.1       cgd 
    379   1.88     lukem 	if (argc != 2) {
    380  1.116  christos 		UPRINTF("usage: %s format\n", argv[0]);
    381   1.76     lukem 		code = -1;
    382   1.76     lukem 		return;
    383   1.76     lukem 	}
    384   1.37     lukem 	fprintf(ttyout, "We only support %s format, sorry.\n", formname);
    385    1.1       cgd 	code = -1;
    386    1.1       cgd }
    387    1.1       cgd 
    388    1.1       cgd /*
    389    1.1       cgd  * Set file transfer structure.
    390    1.1       cgd  */
    391    1.1       cgd /*ARGSUSED*/
    392    1.4       cgd void
    393   1.85     lukem setstruct(int argc, char *argv[])
    394    1.1       cgd {
    395    1.1       cgd 
    396   1.88     lukem 	if (argc != 2) {
    397  1.116  christos 		UPRINTF("usage: %s struct-mode\n", argv[0]);
    398   1.76     lukem 		code = -1;
    399   1.76     lukem 		return;
    400   1.76     lukem 	}
    401   1.37     lukem 	fprintf(ttyout, "We only support %s structure, sorry.\n", structname);
    402    1.1       cgd 	code = -1;
    403    1.1       cgd }
    404    1.1       cgd 
    405    1.1       cgd /*
    406    1.1       cgd  * Send a single file.
    407    1.1       cgd  */
    408    1.4       cgd void
    409   1.85     lukem put(int argc, char *argv[])
    410    1.1       cgd {
    411  1.110  christos 	char buf[MAXPATHLEN];
    412    1.1       cgd 	char *cmd;
    413    1.1       cgd 	int loc = 0;
    414  1.110  christos 	char *locfile;
    415  1.110  christos 	const char *remfile;
    416    1.1       cgd 
    417    1.1       cgd 	if (argc == 2) {
    418    1.1       cgd 		argc++;
    419    1.1       cgd 		argv[2] = argv[1];
    420    1.1       cgd 		loc++;
    421    1.1       cgd 	}
    422   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file")))
    423    1.1       cgd 		goto usage;
    424   1.10     lukem 	if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
    425   1.88     lukem  usage:
    426  1.116  christos 		UPRINTF("usage: %s local-file [remote-file]\n", argv[0]);
    427    1.1       cgd 		code = -1;
    428    1.1       cgd 		return;
    429    1.1       cgd 	}
    430   1.63     lukem 	if ((locfile = globulize(argv[1])) == NULL) {
    431    1.1       cgd 		code = -1;
    432    1.1       cgd 		return;
    433    1.1       cgd 	}
    434   1.63     lukem 	remfile = argv[2];
    435   1.63     lukem 	if (loc)	/* If argv[2] is a copy of the old argv[1], update it */
    436   1.63     lukem 		remfile = locfile;
    437    1.1       cgd 	cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
    438  1.110  christos 	remfile = doprocess(buf, sizeof(buf), remfile,
    439  1.110  christos 		0, loc && ntflag, loc && mapflag);
    440   1.63     lukem 	sendrequest(cmd, locfile, remfile,
    441   1.63     lukem 	    locfile != argv[1] || remfile != argv[2]);
    442   1.63     lukem 	free(locfile);
    443    1.1       cgd }
    444    1.1       cgd 
    445  1.110  christos static const char *
    446  1.110  christos doprocess(char *dst, size_t dlen, const char *src,
    447  1.110  christos     int casef, int transf, int mapf)
    448  1.110  christos {
    449  1.110  christos 	if (casef)
    450  1.110  christos 		src = docase(dst, dlen, src);
    451  1.110  christos 	if (transf)
    452  1.110  christos 		src = dotrans(dst, dlen, src);
    453  1.110  christos 	if (mapf)
    454  1.110  christos 		src = domap(dst, dlen, src);
    455  1.110  christos 	return src;
    456  1.110  christos }
    457  1.110  christos 
    458    1.1       cgd /*
    459    1.1       cgd  * Send multiple files.
    460    1.1       cgd  */
    461    1.4       cgd void
    462   1.85     lukem mput(int argc, char *argv[])
    463    1.1       cgd {
    464    1.4       cgd 	int i;
    465   1.82     lukem 	sigfunc oldintr;
    466    1.1       cgd 	int ointer;
    467  1.110  christos 	const char *tp;
    468    1.1       cgd 
    469   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
    470  1.116  christos 		UPRINTF("usage: %s local-files\n", argv[0]);
    471    1.1       cgd 		code = -1;
    472    1.1       cgd 		return;
    473    1.1       cgd 	}
    474    1.1       cgd 	mflag = 1;
    475   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
    476   1.72     lukem 	if (sigsetjmp(jabort, 1))
    477  1.121     lukem 		mabort(argv[0]);
    478    1.1       cgd 	if (proxy) {
    479   1.63     lukem 		char *cp;
    480    1.1       cgd 
    481   1.19     lukem 		while ((cp = remglob(argv, 0, NULL)) != NULL) {
    482   1.76     lukem 			if (*cp == '\0' || !connected) {
    483    1.1       cgd 				mflag = 0;
    484    1.1       cgd 				continue;
    485    1.1       cgd 			}
    486    1.1       cgd 			if (mflag && confirm(argv[0], cp)) {
    487  1.110  christos 				char buf[MAXPATHLEN];
    488  1.110  christos 				tp = doprocess(buf, sizeof(buf), cp,
    489  1.110  christos 				    mcase, ntflag, mapflag);
    490    1.1       cgd 				sendrequest((sunique) ? "STOU" : "STOR",
    491    1.1       cgd 				    cp, tp, cp != tp || !interactive);
    492    1.1       cgd 				if (!mflag && fromatty) {
    493    1.1       cgd 					ointer = interactive;
    494    1.1       cgd 					interactive = 1;
    495  1.121     lukem 					if (confirm(argv[0], NULL)) {
    496    1.1       cgd 						mflag++;
    497    1.1       cgd 					}
    498    1.1       cgd 					interactive = ointer;
    499    1.1       cgd 				}
    500    1.1       cgd 			}
    501    1.1       cgd 		}
    502   1.72     lukem 		goto cleanupmput;
    503    1.1       cgd 	}
    504   1.76     lukem 	for (i = 1; i < argc && connected; i++) {
    505    1.9     lukem 		char **cpp;
    506    1.4       cgd 		glob_t gl;
    507    1.4       cgd 		int flags;
    508    1.1       cgd 
    509    1.1       cgd 		if (!doglob) {
    510    1.1       cgd 			if (mflag && confirm(argv[0], argv[i])) {
    511  1.110  christos 				char buf[MAXPATHLEN];
    512  1.110  christos 				tp = doprocess(buf, sizeof(buf), argv[i],
    513  1.110  christos 					0, ntflag, mapflag);
    514    1.1       cgd 				sendrequest((sunique) ? "STOU" : "STOR",
    515    1.1       cgd 				    argv[i], tp, tp != argv[i] || !interactive);
    516    1.1       cgd 				if (!mflag && fromatty) {
    517    1.1       cgd 					ointer = interactive;
    518    1.1       cgd 					interactive = 1;
    519  1.121     lukem 					if (confirm(argv[0], NULL)) {
    520    1.1       cgd 						mflag++;
    521    1.1       cgd 					}
    522    1.1       cgd 					interactive = ointer;
    523    1.1       cgd 				}
    524    1.1       cgd 			}
    525    1.1       cgd 			continue;
    526    1.1       cgd 		}
    527    1.4       cgd 
    528    1.4       cgd 		memset(&gl, 0, sizeof(gl));
    529   1.38    kleink 		flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
    530    1.4       cgd 		if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
    531  1.120     lukem 			warnx("Glob pattern `%s' not found", argv[i]);
    532    1.4       cgd 			globfree(&gl);
    533    1.1       cgd 			continue;
    534    1.1       cgd 		}
    535   1.76     lukem 		for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
    536   1.76     lukem 		    cpp++) {
    537    1.1       cgd 			if (mflag && confirm(argv[0], *cpp)) {
    538  1.110  christos 				char buf[MAXPATHLEN];
    539  1.110  christos 				tp = *cpp;
    540  1.110  christos 				tp = doprocess(buf, sizeof(buf), *cpp,
    541  1.110  christos 				    0, ntflag, mapflag);
    542    1.1       cgd 				sendrequest((sunique) ? "STOU" : "STOR",
    543    1.1       cgd 				    *cpp, tp, *cpp != tp || !interactive);
    544    1.1       cgd 				if (!mflag && fromatty) {
    545    1.1       cgd 					ointer = interactive;
    546    1.1       cgd 					interactive = 1;
    547  1.121     lukem 					if (confirm(argv[0], NULL)) {
    548    1.1       cgd 						mflag++;
    549    1.1       cgd 					}
    550    1.1       cgd 					interactive = ointer;
    551    1.1       cgd 				}
    552    1.1       cgd 			}
    553    1.1       cgd 		}
    554    1.4       cgd 		globfree(&gl);
    555    1.1       cgd 	}
    556   1.88     lukem  cleanupmput:
    557   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
    558    1.1       cgd 	mflag = 0;
    559    1.1       cgd }
    560    1.1       cgd 
    561    1.4       cgd void
    562   1.85     lukem reget(int argc, char *argv[])
    563    1.1       cgd {
    564    1.4       cgd 
    565   1.97     lukem 	(void)getit(argc, argv, 1, "r+");
    566    1.1       cgd }
    567    1.1       cgd 
    568    1.4       cgd void
    569   1.85     lukem get(int argc, char *argv[])
    570    1.1       cgd {
    571    1.4       cgd 
    572   1.97     lukem 	(void)getit(argc, argv, 0, restart_point ? "r+" : "w" );
    573    1.1       cgd }
    574    1.1       cgd 
    575    1.1       cgd /*
    576    1.1       cgd  * Receive one file.
    577   1.92     lukem  * If restartit is  1, restart the xfer always.
    578   1.92     lukem  * If restartit is -1, restart the xfer only if the remote file is newer.
    579    1.1       cgd  */
    580    1.4       cgd int
    581   1.85     lukem getit(int argc, char *argv[], int restartit, const char *mode)
    582    1.1       cgd {
    583  1.112     lukem 	int	loc, rval;
    584  1.110  christos 	char	*remfile, *olocfile;
    585  1.110  christos 	const char *locfile;
    586  1.112     lukem 	char	buf[MAXPATHLEN];
    587    1.1       cgd 
    588   1.94     lukem 	loc = rval = 0;
    589    1.1       cgd 	if (argc == 2) {
    590    1.1       cgd 		argc++;
    591    1.1       cgd 		argv[2] = argv[1];
    592    1.1       cgd 		loc++;
    593    1.1       cgd 	}
    594   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file")))
    595    1.1       cgd 		goto usage;
    596   1.10     lukem 	if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
    597   1.88     lukem  usage:
    598  1.116  christos 		UPRINTF("usage: %s remote-file [local-file]\n", argv[0]);
    599    1.1       cgd 		code = -1;
    600    1.1       cgd 		return (0);
    601    1.1       cgd 	}
    602   1.63     lukem 	remfile = argv[1];
    603   1.63     lukem 	if ((olocfile = globulize(argv[2])) == NULL) {
    604    1.1       cgd 		code = -1;
    605    1.1       cgd 		return (0);
    606    1.1       cgd 	}
    607  1.110  christos 	locfile = doprocess(buf, sizeof(buf), olocfile,
    608  1.110  christos 		loc && mcase, loc && ntflag, loc && mapflag);
    609    1.1       cgd 	if (restartit) {
    610    1.1       cgd 		struct stat stbuf;
    611    1.1       cgd 		int ret;
    612    1.1       cgd 
    613   1.88     lukem 		if (! features[FEAT_REST_STREAM]) {
    614   1.88     lukem 			fprintf(ttyout,
    615   1.88     lukem 			    "Restart is not supported by the remote server.\n");
    616   1.88     lukem 			return (0);
    617   1.88     lukem 		}
    618   1.63     lukem 		ret = stat(locfile, &stbuf);
    619    1.1       cgd 		if (restartit == 1) {
    620    1.1       cgd 			if (ret < 0) {
    621  1.120     lukem 				warn("Can't stat `%s'", locfile);
    622   1.27     lukem 				goto freegetit;
    623    1.1       cgd 			}
    624    1.1       cgd 			restart_point = stbuf.st_size;
    625    1.1       cgd 		} else {
    626    1.1       cgd 			if (ret == 0) {
    627   1.10     lukem 				time_t mtime;
    628    1.1       cgd 
    629   1.13     lukem 				mtime = remotemodtime(argv[1], 0);
    630   1.10     lukem 				if (mtime == -1)
    631   1.27     lukem 					goto freegetit;
    632   1.27     lukem 				if (stbuf.st_mtime >= mtime) {
    633   1.27     lukem 					rval = 1;
    634   1.27     lukem 					goto freegetit;
    635   1.27     lukem 				}
    636    1.1       cgd 			}
    637    1.1       cgd 		}
    638    1.1       cgd 	}
    639    1.1       cgd 
    640   1.63     lukem 	recvrequest("RETR", locfile, remfile, mode,
    641   1.63     lukem 	    remfile != argv[1] || locfile != argv[2], loc);
    642    1.1       cgd 	restart_point = 0;
    643   1.88     lukem  freegetit:
    644   1.63     lukem 	(void)free(olocfile);
    645   1.27     lukem 	return (rval);
    646    1.1       cgd }
    647    1.1       cgd 
    648    1.4       cgd /* ARGSUSED */
    649  1.121     lukem static void
    650   1.85     lukem mintr(int signo)
    651    1.1       cgd {
    652   1.72     lukem 
    653   1.72     lukem 	alarmtimer(0);
    654   1.74     lukem 	if (fromatty)
    655   1.74     lukem 		write(fileno(ttyout), "\n", 1);
    656   1.72     lukem 	siglongjmp(jabort, 1);
    657   1.72     lukem }
    658   1.72     lukem 
    659  1.121     lukem static void
    660  1.121     lukem mabort(const char *cmd)
    661   1.72     lukem {
    662   1.10     lukem 	int ointer, oconf;
    663    1.1       cgd 
    664    1.1       cgd 	if (mflag && fromatty) {
    665    1.1       cgd 		ointer = interactive;
    666   1.10     lukem 		oconf = confirmrest;
    667    1.1       cgd 		interactive = 1;
    668   1.10     lukem 		confirmrest = 0;
    669  1.121     lukem 		if (confirm(cmd, NULL)) {
    670    1.1       cgd 			interactive = ointer;
    671   1.10     lukem 			confirmrest = oconf;
    672   1.72     lukem 			return;
    673    1.1       cgd 		}
    674    1.1       cgd 		interactive = ointer;
    675   1.10     lukem 		confirmrest = oconf;
    676    1.1       cgd 	}
    677    1.1       cgd 	mflag = 0;
    678    1.1       cgd }
    679    1.1       cgd 
    680    1.1       cgd /*
    681    1.1       cgd  * Get multiple files.
    682    1.1       cgd  */
    683    1.4       cgd void
    684   1.85     lukem mget(int argc, char *argv[])
    685    1.1       cgd {
    686   1.82     lukem 	sigfunc oldintr;
    687   1.92     lukem 	int ointer;
    688  1.110  christos 	char *cp;
    689  1.110  christos 	const char *tp;
    690   1.92     lukem 	int restartit;
    691    1.1       cgd 
    692   1.88     lukem 	if (argc == 0 ||
    693   1.76     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-files"))) {
    694  1.116  christos 		UPRINTF("usage: %s remote-files\n", argv[0]);
    695    1.1       cgd 		code = -1;
    696    1.1       cgd 		return;
    697    1.1       cgd 	}
    698    1.1       cgd 	mflag = 1;
    699   1.92     lukem 	restart_point = 0;
    700   1.92     lukem 	restartit = 0;
    701   1.92     lukem 	if (strcmp(argv[0], "mreget") == 0) {
    702   1.92     lukem 		if (! features[FEAT_REST_STREAM]) {
    703   1.92     lukem 			fprintf(ttyout,
    704   1.92     lukem 		    "Restart is not supported by the remote server.\n");
    705   1.92     lukem 			return;
    706   1.92     lukem 		}
    707   1.92     lukem 		restartit = 1;
    708   1.92     lukem 	}
    709   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
    710   1.72     lukem 	if (sigsetjmp(jabort, 1))
    711  1.121     lukem 		mabort(argv[0]);
    712   1.19     lukem 	while ((cp = remglob(argv, proxy, NULL)) != NULL) {
    713  1.110  christos 		char buf[MAXPATHLEN];
    714   1.76     lukem 		if (*cp == '\0' || !connected) {
    715    1.1       cgd 			mflag = 0;
    716    1.1       cgd 			continue;
    717    1.1       cgd 		}
    718  1.109     lukem 		if (! mflag)
    719  1.109     lukem 			continue;
    720  1.109     lukem 		if (! fileindir(cp, localcwd)) {
    721  1.109     lukem 			fprintf(ttyout, "Skipping non-relative filename `%s'\n",
    722  1.109     lukem 			    cp);
    723  1.109     lukem 			continue;
    724  1.109     lukem 		}
    725  1.109     lukem 		if (!confirm(argv[0], cp))
    726   1.92     lukem 			continue;
    727  1.110  christos 		tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag);
    728   1.92     lukem 		if (restartit) {
    729   1.92     lukem 			struct stat stbuf;
    730   1.92     lukem 
    731   1.92     lukem 			if (stat(tp, &stbuf) == 0)
    732   1.92     lukem 				restart_point = stbuf.st_size;
    733   1.92     lukem 			else
    734  1.120     lukem 				warn("Can't stat `%s'", tp);
    735   1.92     lukem 		}
    736   1.97     lukem 		recvrequest("RETR", tp, cp, restart_point ? "r+" : "w",
    737   1.92     lukem 		    tp != cp || !interactive, 1);
    738   1.92     lukem 		restart_point = 0;
    739   1.92     lukem 		if (!mflag && fromatty) {
    740   1.92     lukem 			ointer = interactive;
    741   1.92     lukem 			interactive = 1;
    742  1.121     lukem 			if (confirm(argv[0], NULL))
    743   1.92     lukem 				mflag++;
    744   1.92     lukem 			interactive = ointer;
    745    1.1       cgd 		}
    746    1.1       cgd 	}
    747   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
    748    1.1       cgd 	mflag = 0;
    749   1.84     lukem }
    750   1.84     lukem 
    751   1.84     lukem /*
    752   1.84     lukem  * Read list of filenames from a local file and get those
    753   1.84     lukem  */
    754   1.84     lukem void
    755   1.85     lukem fget(int argc, char *argv[])
    756   1.84     lukem {
    757  1.122     lukem 	char	*mode;
    758   1.84     lukem 	FILE	*fp;
    759  1.122     lukem 	char	buf[MAXPATHLEN];
    760   1.84     lukem 
    761   1.84     lukem 	if (argc != 2) {
    762  1.116  christos 		UPRINTF("usage: %s localfile\n", argv[0]);
    763   1.84     lukem 		code = -1;
    764   1.84     lukem 		return;
    765   1.84     lukem 	}
    766   1.84     lukem 
    767   1.84     lukem 	fp = fopen(argv[1], "r");
    768   1.84     lukem 	if (fp == NULL) {
    769  1.120     lukem 		fprintf(ttyout, "Can't open source file %s\n", argv[1]);
    770   1.84     lukem 		code = -1;
    771   1.84     lukem 		return;
    772   1.84     lukem 	}
    773   1.84     lukem 
    774   1.84     lukem 	argv[0] = "get";
    775   1.97     lukem 	mode = restart_point ? "r+" : "w";
    776   1.84     lukem 
    777  1.122     lukem 	while (getline(fp, buf, sizeof(buf), NULL) >= 0) {
    778   1.84     lukem 		if (buf[0] == '\0')
    779   1.84     lukem 			continue;
    780   1.84     lukem 		argv[1] = buf;
    781   1.84     lukem 		(void)getit(argc, argv, 0, mode);
    782   1.84     lukem 	}
    783   1.84     lukem 	fclose(fp);
    784    1.1       cgd }
    785    1.1       cgd 
    786  1.113     lukem const char *
    787   1.85     lukem onoff(int bool)
    788    1.1       cgd {
    789    1.1       cgd 
    790    1.1       cgd 	return (bool ? "on" : "off");
    791    1.1       cgd }
    792    1.1       cgd 
    793    1.1       cgd /*
    794    1.1       cgd  * Show status.
    795    1.1       cgd  */
    796    1.1       cgd /*ARGSUSED*/
    797    1.4       cgd void
    798   1.85     lukem status(int argc, char *argv[])
    799    1.1       cgd {
    800    1.1       cgd 
    801   1.88     lukem 	if (argc == 0) {
    802  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    803   1.76     lukem 		code = -1;
    804   1.76     lukem 		return;
    805   1.76     lukem 	}
    806  1.105    kleink #ifndef NO_STATUS
    807    1.1       cgd 	if (connected)
    808   1.37     lukem 		fprintf(ttyout, "Connected %sto %s.\n",
    809   1.23     lukem 		    connected == -1 ? "and logged in" : "", hostname);
    810    1.1       cgd 	else
    811   1.37     lukem 		fputs("Not connected.\n", ttyout);
    812    1.1       cgd 	if (!proxy) {
    813    1.1       cgd 		pswitch(1);
    814    1.1       cgd 		if (connected) {
    815   1.37     lukem 			fprintf(ttyout, "Connected for proxy commands to %s.\n",
    816   1.10     lukem 			    hostname);
    817    1.1       cgd 		}
    818    1.1       cgd 		else {
    819   1.37     lukem 			fputs("No proxy connection.\n", ttyout);
    820    1.1       cgd 		}
    821    1.1       cgd 		pswitch(0);
    822    1.1       cgd 	}
    823   1.54    itojun 	fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
    824   1.54    itojun 	    *gateserver ? gateserver : "(none)", gateport);
    825   1.76     lukem 	fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
    826   1.76     lukem 	    onoff(passivemode), onoff(activefallback));
    827   1.37     lukem 	fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
    828   1.37     lukem 	    modename, typename, formname, structname);
    829   1.37     lukem 	fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
    830   1.37     lukem 	    onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob));
    831   1.37     lukem 	fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n",
    832   1.37     lukem 	    onoff(sunique), onoff(runique));
    833   1.37     lukem 	fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve));
    834   1.37     lukem 	fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase),
    835   1.37     lukem 	    onoff(crflag));
    836    1.1       cgd 	if (ntflag) {
    837   1.37     lukem 		fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout);
    838    1.1       cgd 	}
    839    1.1       cgd 	else {
    840   1.37     lukem 		fputs("Ntrans: off.\n", ttyout);
    841    1.1       cgd 	}
    842    1.1       cgd 	if (mapflag) {
    843   1.37     lukem 		fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout);
    844    1.1       cgd 	}
    845    1.1       cgd 	else {
    846   1.37     lukem 		fputs("Nmap: off.\n", ttyout);
    847    1.1       cgd 	}
    848   1.37     lukem 	fprintf(ttyout,
    849   1.37     lukem 	    "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
    850   1.11     lukem 	    onoff(hash), mark, onoff(progress));
    851   1.52     lukem 	fprintf(ttyout,
    852   1.52     lukem 	    "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
    853   1.52     lukem 	    onoff(rate_get), rate_get, rate_get_incr);
    854   1.52     lukem 	fprintf(ttyout,
    855   1.52     lukem 	    "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
    856   1.52     lukem 	    onoff(rate_put), rate_put, rate_put_incr);
    857   1.58     lukem 	fprintf(ttyout,
    858   1.58     lukem 	    "Socket buffer sizes: send %d, receive %d.\n",
    859   1.58     lukem 	    sndbuf_size, rcvbuf_size);
    860   1.37     lukem 	fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
    861   1.68     lukem 	fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
    862   1.68     lukem 	    epsv4bad ? " (disabled for this connection)" : "");
    863   1.69     lukem 	fprintf(ttyout, "Command line editing: %s.\n",
    864   1.69     lukem #ifdef NO_EDITCOMPLETE
    865   1.69     lukem 	    "support not compiled in"
    866   1.69     lukem #else	/* !def NO_EDITCOMPLETE */
    867   1.69     lukem 	    onoff(editing)
    868   1.69     lukem #endif	/* !def NO_EDITCOMPLETE */
    869   1.69     lukem 	    );
    870    1.1       cgd 	if (macnum > 0) {
    871  1.104     pooka 		int i;
    872  1.104     pooka 
    873   1.37     lukem 		fputs("Macros:\n", ttyout);
    874    1.1       cgd 		for (i=0; i<macnum; i++) {
    875   1.37     lukem 			fprintf(ttyout, "\t%s\n", macros[i].mac_name);
    876    1.1       cgd 		}
    877    1.1       cgd 	}
    878  1.105    kleink #endif /* !def NO_STATUS */
    879  1.103  christos 	fprintf(ttyout, "Version: %s %s\n", FTP_PRODUCT, FTP_VERSION);
    880    1.1       cgd 	code = 0;
    881    1.1       cgd }
    882    1.1       cgd 
    883    1.1       cgd /*
    884   1.10     lukem  * Toggle a variable
    885   1.10     lukem  */
    886   1.10     lukem int
    887   1.85     lukem togglevar(int argc, char *argv[], int *var, const char *mesg)
    888   1.10     lukem {
    889   1.76     lukem 	if (argc == 1) {
    890   1.10     lukem 		*var = !*var;
    891   1.10     lukem 	} else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
    892   1.10     lukem 		*var = 1;
    893   1.10     lukem 	} else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
    894   1.10     lukem 		*var = 0;
    895   1.10     lukem 	} else {
    896  1.116  christos 		UPRINTF("usage: %s [ on | off ]\n", argv[0]);
    897   1.19     lukem 		return (-1);
    898   1.10     lukem 	}
    899   1.46     lukem 	if (mesg)
    900   1.37     lukem 		fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
    901   1.19     lukem 	return (*var);
    902   1.10     lukem }
    903   1.10     lukem 
    904   1.10     lukem /*
    905    1.1       cgd  * Set beep on cmd completed mode.
    906    1.1       cgd  */
    907    1.1       cgd /*VARARGS*/
    908    1.4       cgd void
    909   1.85     lukem setbell(int argc, char *argv[])
    910    1.1       cgd {
    911    1.1       cgd 
    912   1.10     lukem 	code = togglevar(argc, argv, &bell, "Bell mode");
    913    1.1       cgd }
    914    1.1       cgd 
    915   1.16     lukem /*
    916   1.16     lukem  * Set command line editing
    917   1.16     lukem  */
    918   1.16     lukem /*VARARGS*/
    919   1.16     lukem void
    920   1.85     lukem setedit(int argc, char *argv[])
    921   1.16     lukem {
    922   1.16     lukem 
    923   1.69     lukem #ifdef NO_EDITCOMPLETE
    924   1.88     lukem 	if (argc == 0) {
    925  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
    926   1.76     lukem 		code = -1;
    927   1.76     lukem 		return;
    928   1.76     lukem 	}
    929   1.69     lukem 	if (verbose)
    930   1.69     lukem 		fputs("Editing support not compiled in; ignoring command.\n",
    931   1.69     lukem 		    ttyout);
    932   1.69     lukem #else	/* !def NO_EDITCOMPLETE */
    933   1.16     lukem 	code = togglevar(argc, argv, &editing, "Editing mode");
    934   1.22     lukem 	controlediting();
    935   1.69     lukem #endif	/* !def NO_EDITCOMPLETE */
    936   1.16     lukem }
    937   1.16     lukem 
    938    1.1       cgd /*
    939    1.1       cgd  * Turn on packet tracing.
    940    1.1       cgd  */
    941    1.1       cgd /*VARARGS*/
    942    1.4       cgd void
    943   1.85     lukem settrace(int argc, char *argv[])
    944    1.1       cgd {
    945    1.1       cgd 
    946   1.10     lukem 	code = togglevar(argc, argv, &trace, "Packet tracing");
    947    1.1       cgd }
    948    1.1       cgd 
    949    1.1       cgd /*
    950    1.9     lukem  * Toggle hash mark printing during transfers, or set hash mark bytecount.
    951    1.1       cgd  */
    952    1.1       cgd /*VARARGS*/
    953    1.4       cgd void
    954   1.85     lukem sethash(int argc, char *argv[])
    955    1.1       cgd {
    956   1.10     lukem 	if (argc == 1)
    957    1.9     lukem 		hash = !hash;
    958   1.10     lukem 	else if (argc != 2) {
    959  1.116  christos 		UPRINTF("usage: %s [ on | off | bytecount ]\n",
    960   1.37     lukem 		    argv[0]);
    961   1.10     lukem 		code = -1;
    962   1.10     lukem 		return;
    963   1.10     lukem 	} else if (strcasecmp(argv[1], "on") == 0)
    964   1.10     lukem 		hash = 1;
    965   1.10     lukem 	else if (strcasecmp(argv[1], "off") == 0)
    966   1.10     lukem 		hash = 0;
    967   1.10     lukem 	else {
    968   1.31     lukem 		int nmark;
    969   1.31     lukem 
    970   1.52     lukem 		nmark = strsuftoi(argv[1]);
    971   1.52     lukem 		if (nmark < 1) {
    972   1.37     lukem 			fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
    973   1.37     lukem 			    argv[1]);
    974   1.10     lukem 			code = -1;
    975   1.10     lukem 			return;
    976    1.9     lukem 		}
    977   1.10     lukem 		mark = nmark;
    978   1.10     lukem 		hash = 1;
    979    1.9     lukem 	}
    980   1.37     lukem 	fprintf(ttyout, "Hash mark printing %s", onoff(hash));
    981   1.10     lukem 	if (hash)
    982   1.37     lukem 		fprintf(ttyout, " (%d bytes/hash mark)", mark);
    983   1.37     lukem 	fputs(".\n", ttyout);
    984   1.44     lukem 	if (hash)
    985   1.44     lukem 		progress = 0;
    986   1.10     lukem 	code = hash;
    987    1.1       cgd }
    988    1.1       cgd 
    989    1.1       cgd /*
    990    1.1       cgd  * Turn on printing of server echo's.
    991    1.1       cgd  */
    992    1.1       cgd /*VARARGS*/
    993    1.4       cgd void
    994   1.85     lukem setverbose(int argc, char *argv[])
    995    1.1       cgd {
    996    1.1       cgd 
    997   1.10     lukem 	code = togglevar(argc, argv, &verbose, "Verbose mode");
    998    1.1       cgd }
    999    1.1       cgd 
   1000    1.1       cgd /*
   1001   1.54    itojun  * Toggle PORT/LPRT cmd use before each data connection.
   1002    1.1       cgd  */
   1003    1.1       cgd /*VARARGS*/
   1004    1.4       cgd void
   1005   1.85     lukem setport(int argc, char *argv[])
   1006    1.1       cgd {
   1007    1.1       cgd 
   1008   1.54    itojun 	code = togglevar(argc, argv, &sendport, "Use of PORT/LPRT cmds");
   1009    1.1       cgd }
   1010    1.1       cgd 
   1011    1.1       cgd /*
   1012   1.11     lukem  * Toggle transfer progress bar.
   1013   1.11     lukem  */
   1014   1.11     lukem /*VARARGS*/
   1015   1.11     lukem void
   1016   1.85     lukem setprogress(int argc, char *argv[])
   1017   1.11     lukem {
   1018   1.11     lukem 
   1019   1.11     lukem 	code = togglevar(argc, argv, &progress, "Progress bar");
   1020   1.44     lukem 	if (progress)
   1021   1.44     lukem 		hash = 0;
   1022   1.11     lukem }
   1023   1.11     lukem 
   1024   1.11     lukem /*
   1025   1.27     lukem  * Turn on interactive prompting during mget, mput, and mdelete.
   1026    1.1       cgd  */
   1027    1.1       cgd /*VARARGS*/
   1028    1.4       cgd void
   1029   1.85     lukem setprompt(int argc, char *argv[])
   1030    1.1       cgd {
   1031    1.1       cgd 
   1032   1.10     lukem 	code = togglevar(argc, argv, &interactive, "Interactive mode");
   1033    1.1       cgd }
   1034    1.1       cgd 
   1035    1.1       cgd /*
   1036   1.27     lukem  * Toggle gate-ftp mode, or set gate-ftp server
   1037   1.27     lukem  */
   1038   1.27     lukem /*VARARGS*/
   1039   1.27     lukem void
   1040   1.85     lukem setgate(int argc, char *argv[])
   1041   1.27     lukem {
   1042   1.27     lukem 	static char gsbuf[MAXHOSTNAMELEN];
   1043   1.27     lukem 
   1044   1.88     lukem 	if (argc == 0 || argc > 3) {
   1045  1.116  christos 		UPRINTF(
   1046   1.76     lukem 		    "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
   1047   1.27     lukem 		code = -1;
   1048   1.27     lukem 		return;
   1049   1.27     lukem 	} else if (argc < 2) {
   1050   1.27     lukem 		gatemode = !gatemode;
   1051   1.27     lukem 	} else {
   1052   1.27     lukem 		if (argc == 2 && strcasecmp(argv[1], "on") == 0)
   1053   1.27     lukem 			gatemode = 1;
   1054   1.27     lukem 		else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
   1055   1.27     lukem 			gatemode = 0;
   1056   1.27     lukem 		else {
   1057   1.59     lukem 			if (argc == 3)
   1058  1.117  christos 				gateport = ftp_strdup(argv[2]);
   1059   1.63     lukem 			(void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
   1060   1.27     lukem 			gateserver = gsbuf;
   1061   1.27     lukem 			gatemode = 1;
   1062   1.27     lukem 		}
   1063   1.27     lukem 	}
   1064   1.27     lukem 	if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
   1065   1.37     lukem 		fprintf(ttyout,
   1066   1.27     lukem 		    "Disabling gate-ftp mode - no gate-ftp server defined.\n");
   1067   1.27     lukem 		gatemode = 0;
   1068   1.27     lukem 	} else {
   1069   1.54    itojun 		fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n",
   1070   1.37     lukem 		    onoff(gatemode), *gateserver ? gateserver : "(none)",
   1071   1.54    itojun 		    gateport);
   1072   1.27     lukem 	}
   1073   1.27     lukem 	code = gatemode;
   1074   1.27     lukem }
   1075   1.27     lukem 
   1076   1.27     lukem /*
   1077   1.27     lukem  * Toggle metacharacter interpretation on local file names.
   1078    1.1       cgd  */
   1079    1.1       cgd /*VARARGS*/
   1080    1.4       cgd void
   1081   1.85     lukem setglob(int argc, char *argv[])
   1082    1.1       cgd {
   1083    1.9     lukem 
   1084   1.10     lukem 	code = togglevar(argc, argv, &doglob, "Globbing");
   1085   1.10     lukem }
   1086   1.10     lukem 
   1087   1.10     lukem /*
   1088   1.40     lukem  * Toggle preserving modification times on retrieved files.
   1089   1.10     lukem  */
   1090   1.10     lukem /*VARARGS*/
   1091   1.10     lukem void
   1092   1.85     lukem setpreserve(int argc, char *argv[])
   1093   1.10     lukem {
   1094   1.10     lukem 
   1095   1.10     lukem 	code = togglevar(argc, argv, &preserve, "Preserve modification times");
   1096    1.1       cgd }
   1097    1.1       cgd 
   1098    1.1       cgd /*
   1099   1.27     lukem  * Set debugging mode on/off and/or set level of debugging.
   1100    1.1       cgd  */
   1101    1.1       cgd /*VARARGS*/
   1102    1.4       cgd void
   1103   1.85     lukem setdebug(int argc, char *argv[])
   1104    1.1       cgd {
   1105   1.88     lukem 	if (argc == 0 || argc > 2) {
   1106  1.116  christos 		UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
   1107   1.10     lukem 		code = -1;
   1108   1.10     lukem 		return;
   1109   1.10     lukem 	} else if (argc == 2) {
   1110   1.10     lukem 		if (strcasecmp(argv[1], "on") == 0)
   1111  1.118  christos 			ftp_debug = 1;
   1112   1.10     lukem 		else if (strcasecmp(argv[1], "off") == 0)
   1113  1.118  christos 			ftp_debug = 0;
   1114   1.10     lukem 		else {
   1115   1.52     lukem 			int val;
   1116   1.25     lukem 
   1117   1.52     lukem 			val = strsuftoi(argv[1]);
   1118   1.52     lukem 			if (val < 0) {
   1119   1.37     lukem 				fprintf(ttyout, "%s: bad debugging value.\n",
   1120   1.37     lukem 				    argv[1]);
   1121   1.10     lukem 				code = -1;
   1122   1.10     lukem 				return;
   1123   1.10     lukem 			}
   1124  1.118  christos 			ftp_debug = val;
   1125    1.1       cgd 		}
   1126    1.1       cgd 	} else
   1127  1.118  christos 		ftp_debug = !ftp_debug;
   1128  1.118  christos 	if (ftp_debug)
   1129    1.1       cgd 		options |= SO_DEBUG;
   1130    1.1       cgd 	else
   1131    1.1       cgd 		options &= ~SO_DEBUG;
   1132  1.118  christos 	fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
   1133  1.118  christos 	code = ftp_debug > 0;
   1134    1.1       cgd }
   1135    1.1       cgd 
   1136    1.1       cgd /*
   1137   1.27     lukem  * Set current working directory on remote machine.
   1138    1.1       cgd  */
   1139    1.4       cgd void
   1140   1.85     lukem cd(int argc, char *argv[])
   1141    1.1       cgd {
   1142   1.16     lukem 	int r;
   1143    1.1       cgd 
   1144   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1145   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-directory"))) {
   1146  1.116  christos 		UPRINTF("usage: %s remote-directory\n", argv[0]);
   1147    1.1       cgd 		code = -1;
   1148    1.1       cgd 		return;
   1149    1.1       cgd 	}
   1150   1.17     veego 	r = command("CWD %s", argv[1]);
   1151   1.16     lukem 	if (r == ERROR && code == 500) {
   1152    1.1       cgd 		if (verbose)
   1153   1.37     lukem 			fputs("CWD command not recognized, trying XCWD.\n",
   1154   1.37     lukem 			    ttyout);
   1155   1.16     lukem 		r = command("XCWD %s", argv[1]);
   1156    1.1       cgd 	}
   1157   1.79     lukem 	if (r == COMPLETE) {
   1158   1.16     lukem 		dirchange = 1;
   1159  1.109     lukem 		updateremotecwd();
   1160   1.79     lukem 	}
   1161    1.1       cgd }
   1162    1.1       cgd 
   1163    1.1       cgd /*
   1164   1.27     lukem  * Set current working directory on local machine.
   1165    1.1       cgd  */
   1166    1.4       cgd void
   1167   1.85     lukem lcd(int argc, char *argv[])
   1168    1.1       cgd {
   1169   1.63     lukem 	char *locdir;
   1170    1.1       cgd 
   1171   1.76     lukem 	code = -1;
   1172   1.76     lukem 	if (argc == 1) {
   1173   1.64     lukem 		argc++;
   1174   1.92     lukem 		argv[1] = localhome;
   1175   1.64     lukem 	}
   1176    1.1       cgd 	if (argc != 2) {
   1177  1.116  christos 		UPRINTF("usage: %s [local-directory]\n", argv[0]);
   1178    1.1       cgd 		return;
   1179    1.1       cgd 	}
   1180   1.76     lukem 	if ((locdir = globulize(argv[1])) == NULL)
   1181    1.1       cgd 		return;
   1182  1.109     lukem 	if (chdir(locdir) == -1)
   1183  1.120     lukem 		warn("Can't chdir `%s'", locdir);
   1184   1.76     lukem 	else {
   1185  1.109     lukem 		updatelocalcwd();
   1186  1.109     lukem 		if (localcwd[0]) {
   1187  1.109     lukem 			fprintf(ttyout, "Local directory now: %s\n", localcwd);
   1188   1.76     lukem 			code = 0;
   1189  1.109     lukem 		} else {
   1190  1.109     lukem 			fprintf(ttyout, "Unable to determine local directory\n");
   1191  1.109     lukem 		}
   1192    1.1       cgd 	}
   1193   1.63     lukem 	(void)free(locdir);
   1194    1.1       cgd }
   1195    1.1       cgd 
   1196    1.1       cgd /*
   1197    1.1       cgd  * Delete a single file.
   1198    1.1       cgd  */
   1199    1.4       cgd void
   1200   1.85     lukem delete(int argc, char *argv[])
   1201    1.1       cgd {
   1202    1.1       cgd 
   1203   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1204   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   1205  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   1206    1.1       cgd 		code = -1;
   1207    1.1       cgd 		return;
   1208    1.1       cgd 	}
   1209  1.101     lukem 	if (command("DELE %s", argv[1]) == COMPLETE)
   1210  1.101     lukem 		dirchange = 1;
   1211    1.1       cgd }
   1212    1.1       cgd 
   1213    1.1       cgd /*
   1214    1.1       cgd  * Delete multiple files.
   1215    1.1       cgd  */
   1216    1.4       cgd void
   1217   1.85     lukem mdelete(int argc, char *argv[])
   1218    1.1       cgd {
   1219   1.82     lukem 	sigfunc oldintr;
   1220    1.1       cgd 	int ointer;
   1221    1.1       cgd 	char *cp;
   1222    1.1       cgd 
   1223   1.88     lukem 	if (argc == 0 ||
   1224   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-files"))) {
   1225  1.116  christos 		UPRINTF("usage: %s [remote-files]\n", argv[0]);
   1226    1.1       cgd 		code = -1;
   1227    1.1       cgd 		return;
   1228    1.1       cgd 	}
   1229    1.1       cgd 	mflag = 1;
   1230   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
   1231   1.72     lukem 	if (sigsetjmp(jabort, 1))
   1232  1.121     lukem 		mabort(argv[0]);
   1233   1.19     lukem 	while ((cp = remglob(argv, 0, NULL)) != NULL) {
   1234    1.1       cgd 		if (*cp == '\0') {
   1235    1.1       cgd 			mflag = 0;
   1236    1.1       cgd 			continue;
   1237    1.1       cgd 		}
   1238    1.1       cgd 		if (mflag && confirm(argv[0], cp)) {
   1239  1.101     lukem 			if (command("DELE %s", cp) == COMPLETE)
   1240  1.101     lukem 				dirchange = 1;
   1241    1.1       cgd 			if (!mflag && fromatty) {
   1242    1.1       cgd 				ointer = interactive;
   1243    1.1       cgd 				interactive = 1;
   1244  1.121     lukem 				if (confirm(argv[0], NULL)) {
   1245    1.1       cgd 					mflag++;
   1246    1.1       cgd 				}
   1247    1.1       cgd 				interactive = ointer;
   1248    1.1       cgd 			}
   1249    1.1       cgd 		}
   1250    1.1       cgd 	}
   1251   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
   1252    1.1       cgd 	mflag = 0;
   1253    1.1       cgd }
   1254    1.1       cgd 
   1255    1.1       cgd /*
   1256    1.1       cgd  * Rename a remote file.
   1257    1.1       cgd  */
   1258    1.4       cgd void
   1259   1.85     lukem renamefile(int argc, char *argv[])
   1260    1.1       cgd {
   1261    1.1       cgd 
   1262   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name")))
   1263    1.1       cgd 		goto usage;
   1264   1.10     lukem 	if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
   1265   1.88     lukem  usage:
   1266  1.116  christos 		UPRINTF("usage: %s from-name to-name\n", argv[0]);
   1267    1.1       cgd 		code = -1;
   1268    1.1       cgd 		return;
   1269    1.1       cgd 	}
   1270  1.101     lukem 	if (command("RNFR %s", argv[1]) == CONTINUE &&
   1271  1.101     lukem 	    command("RNTO %s", argv[2]) == COMPLETE)
   1272  1.101     lukem 		dirchange = 1;
   1273    1.1       cgd }
   1274    1.1       cgd 
   1275    1.1       cgd /*
   1276   1.27     lukem  * Get a directory listing of remote files.
   1277   1.88     lukem  * Supports being invoked as:
   1278   1.88     lukem  *	cmd		runs
   1279   1.88     lukem  *	---		----
   1280   1.88     lukem  *	dir, ls		LIST
   1281   1.88     lukem  *	mlsd		MLSD
   1282   1.88     lukem  *	nlist		NLST
   1283   1.88     lukem  *	pdir, pls	LIST |$PAGER
   1284   1.88     lukem  *	mmlsd		MLSD |$PAGER
   1285    1.1       cgd  */
   1286    1.4       cgd void
   1287   1.85     lukem ls(int argc, char *argv[])
   1288    1.1       cgd {
   1289   1.10     lukem 	const char *cmd;
   1290   1.63     lukem 	char *remdir, *locfile;
   1291   1.88     lukem 	int freelocfile, pagecmd, mlsdcmd;
   1292    1.1       cgd 
   1293   1.63     lukem 	remdir = NULL;
   1294   1.63     lukem 	locfile = "-";
   1295   1.88     lukem 	freelocfile = pagecmd = mlsdcmd = 0;
   1296   1.63     lukem 			/*
   1297   1.88     lukem 			 * the only commands that start with `p' are
   1298   1.88     lukem 			 * the `pager' versions.
   1299   1.63     lukem 			 */
   1300   1.63     lukem 	if (argv[0][0] == 'p')
   1301   1.63     lukem 		pagecmd = 1;
   1302   1.88     lukem 	if (strcmp(argv[0] + pagecmd , "mlsd") == 0) {
   1303   1.88     lukem 		if (! features[FEAT_MLST]) {
   1304   1.88     lukem 			fprintf(ttyout,
   1305   1.88     lukem 			   "MLSD is not supported by the remote server.\n");
   1306   1.88     lukem 			return;
   1307   1.88     lukem 		}
   1308   1.88     lukem 		mlsdcmd = 1;
   1309   1.88     lukem 	}
   1310   1.88     lukem 	if (argc == 0)
   1311   1.76     lukem 		goto usage;
   1312   1.63     lukem 
   1313   1.88     lukem 	if (mlsdcmd)
   1314   1.88     lukem 		cmd = "MLSD";
   1315   1.88     lukem 	else if (strcmp(argv[0] + pagecmd, "nlist") == 0)
   1316   1.86     lukem 		cmd = "NLST";
   1317   1.88     lukem 	else
   1318   1.88     lukem 		cmd = "LIST";
   1319   1.63     lukem 
   1320   1.63     lukem 	if (argc > 1)
   1321   1.63     lukem 		remdir = argv[1];
   1322   1.63     lukem 	if (argc > 2)
   1323   1.63     lukem 		locfile = argv[2];
   1324   1.88     lukem 	if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
   1325   1.76     lukem  usage:
   1326   1.88     lukem 		if (pagecmd || mlsdcmd)
   1327  1.116  christos 			UPRINTF("usage: %s [remote-path]\n", argv[0]);
   1328   1.63     lukem 		else
   1329  1.116  christos 			UPRINTF("usage: %s [remote-path [local-file]]\n",
   1330   1.63     lukem 			    argv[0]);
   1331    1.1       cgd 		code = -1;
   1332   1.63     lukem 		goto freels;
   1333    1.1       cgd 	}
   1334   1.63     lukem 
   1335   1.63     lukem 	if (pagecmd) {
   1336   1.63     lukem 		char *p;
   1337  1.114     lukem 		size_t len;
   1338   1.63     lukem 
   1339   1.76     lukem 		p = getoptionvalue("pager");
   1340   1.76     lukem 		if (EMPTYSTRING(p))
   1341   1.76     lukem 			p = DEFAULTPAGER;
   1342   1.63     lukem 		len = strlen(p) + 2;
   1343  1.117  christos 		locfile = ftp_malloc(len);
   1344   1.63     lukem 		locfile[0] = '|';
   1345   1.63     lukem 		(void)strlcpy(locfile + 1, p, len - 1);
   1346   1.63     lukem 		freelocfile = 1;
   1347   1.63     lukem 	} else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
   1348   1.63     lukem 		if ((locfile = globulize(locfile)) == NULL ||
   1349   1.63     lukem 		    !confirm("output to local-file:", locfile)) {
   1350    1.1       cgd 			code = -1;
   1351   1.27     lukem 			goto freels;
   1352   1.63     lukem 		}
   1353   1.63     lukem 		freelocfile = 1;
   1354    1.1       cgd 	}
   1355   1.63     lukem 	recvrequest(cmd, locfile, remdir, "w", 0, 0);
   1356   1.88     lukem  freels:
   1357   1.63     lukem 	if (freelocfile && locfile)
   1358   1.63     lukem 		(void)free(locfile);
   1359    1.1       cgd }
   1360    1.1       cgd 
   1361    1.1       cgd /*
   1362   1.27     lukem  * Get a directory listing of multiple remote files.
   1363    1.1       cgd  */
   1364    1.4       cgd void
   1365   1.85     lukem mls(int argc, char *argv[])
   1366    1.1       cgd {
   1367   1.82     lukem 	sigfunc oldintr;
   1368    1.1       cgd 	int ointer, i;
   1369   1.25     lukem 	int dolist;
   1370   1.96     lukem 	char *mode, *dest, *odest;
   1371    1.1       cgd 
   1372   1.88     lukem 	if (argc == 0)
   1373   1.76     lukem 		goto usage;
   1374    1.1       cgd 	if (argc < 2 && !another(&argc, &argv, "remote-files"))
   1375    1.1       cgd 		goto usage;
   1376    1.1       cgd 	if (argc < 3 && !another(&argc, &argv, "local-file")) {
   1377   1.88     lukem  usage:
   1378  1.116  christos 		UPRINTF("usage: %s remote-files local-file\n", argv[0]);
   1379    1.1       cgd 		code = -1;
   1380    1.1       cgd 		return;
   1381    1.1       cgd 	}
   1382   1.27     lukem 	odest = dest = argv[argc - 1];
   1383    1.1       cgd 	argv[argc - 1] = NULL;
   1384    1.1       cgd 	if (strcmp(dest, "-") && *dest != '|')
   1385   1.63     lukem 		if (((dest = globulize(dest)) == NULL) ||
   1386    1.1       cgd 		    !confirm("output to local-file:", dest)) {
   1387    1.1       cgd 			code = -1;
   1388    1.1       cgd 			return;
   1389    1.1       cgd 	}
   1390   1.25     lukem 	dolist = strcmp(argv[0], "mls");
   1391    1.1       cgd 	mflag = 1;
   1392   1.72     lukem 	oldintr = xsignal(SIGINT, mintr);
   1393   1.72     lukem 	if (sigsetjmp(jabort, 1))
   1394  1.121     lukem 		mabort(argv[0]);
   1395   1.76     lukem 	for (i = 1; mflag && i < argc-1 && connected; i++) {
   1396   1.96     lukem 		mode = (i == 1) ? "w" : "a";
   1397   1.27     lukem 		recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
   1398   1.27     lukem 		    0, 0);
   1399    1.1       cgd 		if (!mflag && fromatty) {
   1400    1.1       cgd 			ointer = interactive;
   1401    1.1       cgd 			interactive = 1;
   1402  1.121     lukem 			if (confirm(argv[0], NULL)) {
   1403  1.111    simonb 				mflag++;
   1404    1.1       cgd 			}
   1405    1.1       cgd 			interactive = ointer;
   1406    1.1       cgd 		}
   1407    1.1       cgd 	}
   1408   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
   1409    1.1       cgd 	mflag = 0;
   1410   1.27     lukem 	if (dest != odest)			/* free up after globulize() */
   1411   1.27     lukem 		free(dest);
   1412    1.1       cgd }
   1413    1.1       cgd 
   1414    1.1       cgd /*
   1415    1.1       cgd  * Do a shell escape
   1416    1.1       cgd  */
   1417    1.1       cgd /*ARGSUSED*/
   1418    1.4       cgd void
   1419   1.85     lukem shell(int argc, char *argv[])
   1420    1.1       cgd {
   1421    1.4       cgd 	pid_t pid;
   1422  1.106     lukem 	sigfunc oldintr;
   1423   1.13     lukem 	char shellnam[MAXPATHLEN], *shell, *namep;
   1424   1.29     lukem 	int wait_status;
   1425    1.1       cgd 
   1426   1.88     lukem 	if (argc == 0) {
   1427  1.116  christos 		UPRINTF("usage: %s [command [args]]\n", argv[0]);
   1428   1.76     lukem 		code = -1;
   1429   1.76     lukem 		return;
   1430   1.76     lukem 	}
   1431  1.106     lukem 	oldintr = xsignal(SIGINT, SIG_IGN);
   1432    1.1       cgd 	if ((pid = fork()) == 0) {
   1433    1.1       cgd 		for (pid = 3; pid < 20; pid++)
   1434   1.19     lukem 			(void)close(pid);
   1435   1.62     lukem 		(void)xsignal(SIGINT, SIG_DFL);
   1436    1.1       cgd 		shell = getenv("SHELL");
   1437    1.1       cgd 		if (shell == NULL)
   1438    1.1       cgd 			shell = _PATH_BSHELL;
   1439   1.10     lukem 		namep = strrchr(shell, '/');
   1440    1.1       cgd 		if (namep == NULL)
   1441    1.1       cgd 			namep = shell;
   1442   1.71     lukem 		else
   1443   1.71     lukem 			namep++;
   1444   1.71     lukem 		(void)strlcpy(shellnam, namep, sizeof(shellnam));
   1445  1.118  christos 		if (ftp_debug) {
   1446   1.37     lukem 			fputs(shell, ttyout);
   1447   1.37     lukem 			putc('\n', ttyout);
   1448    1.1       cgd 		}
   1449    1.1       cgd 		if (argc > 1) {
   1450   1.10     lukem 			execl(shell, shellnam, "-c", altarg, (char *)0);
   1451    1.1       cgd 		}
   1452    1.1       cgd 		else {
   1453   1.10     lukem 			execl(shell, shellnam, (char *)0);
   1454    1.1       cgd 		}
   1455  1.120     lukem 		warn("Can't execute `%s'", shell);
   1456    1.1       cgd 		code = -1;
   1457    1.1       cgd 		exit(1);
   1458    1.4       cgd 	}
   1459    1.1       cgd 	if (pid > 0)
   1460   1.29     lukem 		while (wait(&wait_status) != pid)
   1461    1.1       cgd 			;
   1462  1.106     lukem 	(void)xsignal(SIGINT, oldintr);
   1463    1.1       cgd 	if (pid == -1) {
   1464  1.120     lukem 		warn("Can't fork a subshell; try again later");
   1465    1.1       cgd 		code = -1;
   1466   1.76     lukem 	} else
   1467    1.1       cgd 		code = 0;
   1468    1.1       cgd }
   1469    1.1       cgd 
   1470    1.1       cgd /*
   1471    1.1       cgd  * Send new user information (re-login)
   1472    1.1       cgd  */
   1473    1.4       cgd void
   1474   1.85     lukem user(int argc, char *argv[])
   1475    1.1       cgd {
   1476  1.115     lukem 	char *password;
   1477  1.119     lukem 	char emptypass[] = "";
   1478    1.1       cgd 	int n, aflag = 0;
   1479    1.1       cgd 
   1480   1.88     lukem 	if (argc == 0)
   1481   1.76     lukem 		goto usage;
   1482    1.1       cgd 	if (argc < 2)
   1483   1.19     lukem 		(void)another(&argc, &argv, "username");
   1484    1.1       cgd 	if (argc < 2 || argc > 4) {
   1485   1.76     lukem  usage:
   1486  1.116  christos 		UPRINTF("usage: %s username [password [account]]\n",
   1487   1.37     lukem 		    argv[0]);
   1488    1.1       cgd 		code = -1;
   1489    1.4       cgd 		return;
   1490    1.1       cgd 	}
   1491    1.1       cgd 	n = command("USER %s", argv[1]);
   1492    1.1       cgd 	if (n == CONTINUE) {
   1493   1.49     lukem 		if (argc < 3) {
   1494  1.115     lukem 			password = getpass("Password: ");
   1495  1.119     lukem 			if (password == NULL)
   1496  1.119     lukem 				password = emptypass;
   1497  1.115     lukem 		} else {
   1498  1.115     lukem 			password = argv[2];
   1499   1.49     lukem 		}
   1500  1.115     lukem 		n = command("PASS %s", password);
   1501  1.115     lukem 		memset(password, 0, strlen(password));
   1502    1.1       cgd 	}
   1503    1.1       cgd 	if (n == CONTINUE) {
   1504  1.115     lukem 		aflag++;
   1505    1.1       cgd 		if (argc < 4) {
   1506  1.115     lukem 			password = getpass("Account: ");
   1507  1.119     lukem 			if (password == NULL)
   1508  1.119     lukem 				password = emptypass;
   1509  1.115     lukem 		} else {
   1510  1.115     lukem 			password = argv[3];
   1511    1.1       cgd 		}
   1512  1.115     lukem 		n = command("ACCT %s", password);
   1513  1.115     lukem 		memset(password, 0, strlen(password));
   1514    1.1       cgd 	}
   1515    1.1       cgd 	if (n != COMPLETE) {
   1516   1.37     lukem 		fputs("Login failed.\n", ttyout);
   1517    1.4       cgd 		return;
   1518    1.1       cgd 	}
   1519    1.1       cgd 	if (!aflag && argc == 4) {
   1520  1.115     lukem 		password = argv[3];
   1521  1.115     lukem 		(void)command("ACCT %s", password);
   1522  1.115     lukem 		memset(password, 0, strlen(password));
   1523    1.1       cgd 	}
   1524   1.23     lukem 	connected = -1;
   1525   1.88     lukem 	getremoteinfo();
   1526    1.1       cgd }
   1527    1.1       cgd 
   1528    1.1       cgd /*
   1529   1.10     lukem  * Print working directory on remote machine.
   1530    1.1       cgd  */
   1531    1.1       cgd /*VARARGS*/
   1532    1.4       cgd void
   1533   1.85     lukem pwd(int argc, char *argv[])
   1534    1.1       cgd {
   1535    1.1       cgd 
   1536  1.109     lukem 	code = -1;
   1537  1.109     lukem 	if (argc != 1) {
   1538  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1539   1.76     lukem 		return;
   1540   1.76     lukem 	}
   1541  1.109     lukem 	if (! remotecwd[0])
   1542  1.109     lukem 		updateremotecwd();
   1543  1.109     lukem 	if (! remotecwd[0])
   1544  1.109     lukem 		fprintf(ttyout, "Unable to determine remote directory\n");
   1545  1.109     lukem 	else {
   1546  1.109     lukem 		fprintf(ttyout, "Remote directory: %s\n", remotecwd);
   1547  1.109     lukem 		code = 0;
   1548    1.1       cgd 	}
   1549    1.1       cgd }
   1550    1.1       cgd 
   1551    1.1       cgd /*
   1552   1.10     lukem  * Print working directory on local machine.
   1553   1.10     lukem  */
   1554   1.10     lukem void
   1555   1.85     lukem lpwd(int argc, char *argv[])
   1556   1.10     lukem {
   1557   1.10     lukem 
   1558  1.109     lukem 	code = -1;
   1559  1.109     lukem 	if (argc != 1) {
   1560  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1561   1.76     lukem 		return;
   1562   1.76     lukem 	}
   1563  1.109     lukem 	if (! localcwd[0])
   1564  1.109     lukem 		updatelocalcwd();
   1565  1.109     lukem 	if (! localcwd[0])
   1566  1.109     lukem 		fprintf(ttyout, "Unable to determine local directory\n");
   1567  1.109     lukem 	else {
   1568  1.109     lukem 		fprintf(ttyout, "Local directory: %s\n", localcwd);
   1569   1.76     lukem 		code = 0;
   1570   1.76     lukem 	}
   1571   1.10     lukem }
   1572   1.10     lukem 
   1573   1.10     lukem /*
   1574    1.1       cgd  * Make a directory.
   1575    1.1       cgd  */
   1576    1.4       cgd void
   1577   1.85     lukem makedir(int argc, char *argv[])
   1578    1.1       cgd {
   1579  1.101     lukem 	int r;
   1580    1.1       cgd 
   1581   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1582   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "directory-name"))) {
   1583  1.116  christos 		UPRINTF("usage: %s directory-name\n", argv[0]);
   1584    1.1       cgd 		code = -1;
   1585    1.1       cgd 		return;
   1586    1.1       cgd 	}
   1587  1.101     lukem 	r = command("MKD %s", argv[1]);
   1588  1.101     lukem 	if (r == ERROR && code == 500) {
   1589    1.1       cgd 		if (verbose)
   1590   1.37     lukem 			fputs("MKD command not recognized, trying XMKD.\n",
   1591   1.37     lukem 			    ttyout);
   1592  1.101     lukem 		r = command("XMKD %s", argv[1]);
   1593    1.1       cgd 	}
   1594  1.101     lukem 	if (r == COMPLETE)
   1595  1.101     lukem 		dirchange = 1;
   1596    1.1       cgd }
   1597    1.1       cgd 
   1598    1.1       cgd /*
   1599    1.1       cgd  * Remove a directory.
   1600    1.1       cgd  */
   1601    1.4       cgd void
   1602   1.85     lukem removedir(int argc, char *argv[])
   1603    1.1       cgd {
   1604  1.101     lukem 	int r;
   1605    1.1       cgd 
   1606   1.88     lukem 	if (argc == 0 || argc > 2 ||
   1607   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "directory-name"))) {
   1608  1.116  christos 		UPRINTF("usage: %s directory-name\n", argv[0]);
   1609    1.1       cgd 		code = -1;
   1610    1.1       cgd 		return;
   1611    1.1       cgd 	}
   1612  1.101     lukem 	r = command("RMD %s", argv[1]);
   1613  1.101     lukem 	if (r == ERROR && code == 500) {
   1614    1.1       cgd 		if (verbose)
   1615   1.37     lukem 			fputs("RMD command not recognized, trying XRMD.\n",
   1616   1.37     lukem 			    ttyout);
   1617  1.101     lukem 		r = command("XRMD %s", argv[1]);
   1618    1.1       cgd 	}
   1619  1.101     lukem 	if (r == COMPLETE)
   1620  1.101     lukem 		dirchange = 1;
   1621    1.1       cgd }
   1622    1.1       cgd 
   1623    1.1       cgd /*
   1624    1.1       cgd  * Send a line, verbatim, to the remote machine.
   1625    1.1       cgd  */
   1626    1.4       cgd void
   1627   1.85     lukem quote(int argc, char *argv[])
   1628    1.1       cgd {
   1629    1.1       cgd 
   1630   1.88     lukem 	if (argc == 0 ||
   1631   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "command line to send"))) {
   1632  1.116  christos 		UPRINTF("usage: %s line-to-send\n", argv[0]);
   1633    1.1       cgd 		code = -1;
   1634    1.1       cgd 		return;
   1635    1.1       cgd 	}
   1636    1.1       cgd 	quote1("", argc, argv);
   1637    1.1       cgd }
   1638    1.1       cgd 
   1639    1.1       cgd /*
   1640    1.1       cgd  * Send a SITE command to the remote machine.  The line
   1641    1.1       cgd  * is sent verbatim to the remote machine, except that the
   1642    1.1       cgd  * word "SITE" is added at the front.
   1643    1.1       cgd  */
   1644    1.4       cgd void
   1645   1.85     lukem site(int argc, char *argv[])
   1646    1.1       cgd {
   1647    1.1       cgd 
   1648   1.88     lukem 	if (argc == 0 ||
   1649   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
   1650  1.116  christos 		UPRINTF("usage: %s line-to-send\n", argv[0]);
   1651    1.1       cgd 		code = -1;
   1652    1.1       cgd 		return;
   1653    1.1       cgd 	}
   1654    1.1       cgd 	quote1("SITE ", argc, argv);
   1655    1.1       cgd }
   1656    1.1       cgd 
   1657    1.1       cgd /*
   1658    1.1       cgd  * Turn argv[1..argc) into a space-separated string, then prepend initial text.
   1659    1.1       cgd  * Send the result as a one-line command and get response.
   1660    1.1       cgd  */
   1661    1.4       cgd void
   1662   1.85     lukem quote1(const char *initial, int argc, char *argv[])
   1663    1.1       cgd {
   1664   1.63     lukem 	int i;
   1665    1.1       cgd 	char buf[BUFSIZ];		/* must be >= sizeof(line) */
   1666    1.1       cgd 
   1667   1.63     lukem 	(void)strlcpy(buf, initial, sizeof(buf));
   1668   1.63     lukem 	for (i = 1; i < argc; i++) {
   1669   1.63     lukem 		(void)strlcat(buf, argv[i], sizeof(buf));
   1670   1.63     lukem 		if (i < (argc - 1))
   1671   1.63     lukem 			(void)strlcat(buf, " ", sizeof(buf));
   1672    1.1       cgd 	}
   1673   1.43     lukem 	if (command("%s", buf) == PRELIM) {
   1674    1.4       cgd 		while (getreply(0) == PRELIM)
   1675    1.4       cgd 			continue;
   1676    1.1       cgd 	}
   1677  1.101     lukem 	dirchange = 1;
   1678    1.1       cgd }
   1679    1.1       cgd 
   1680    1.4       cgd void
   1681   1.85     lukem do_chmod(int argc, char *argv[])
   1682    1.1       cgd {
   1683    1.1       cgd 
   1684   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode")))
   1685    1.1       cgd 		goto usage;
   1686   1.76     lukem 	if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
   1687   1.88     lukem  usage:
   1688  1.116  christos 		UPRINTF("usage: %s mode remote-file\n", argv[0]);
   1689    1.1       cgd 		code = -1;
   1690    1.1       cgd 		return;
   1691    1.1       cgd 	}
   1692   1.19     lukem 	(void)command("SITE CHMOD %s %s", argv[1], argv[2]);
   1693    1.1       cgd }
   1694    1.1       cgd 
   1695  1.112     lukem #define COMMAND_1ARG(argc, argv, cmd)			\
   1696   1.91        is 	if (argc == 1)					\
   1697   1.91        is 		command(cmd);				\
   1698   1.91        is 	else						\
   1699   1.91        is 		command(cmd " %s", argv[1])
   1700   1.91        is 
   1701    1.4       cgd void
   1702   1.85     lukem do_umask(int argc, char *argv[])
   1703    1.1       cgd {
   1704    1.1       cgd 	int oldverbose = verbose;
   1705    1.1       cgd 
   1706   1.88     lukem 	if (argc == 0) {
   1707  1.116  christos 		UPRINTF("usage: %s [umask]\n", argv[0]);
   1708   1.76     lukem 		code = -1;
   1709   1.76     lukem 		return;
   1710   1.76     lukem 	}
   1711    1.1       cgd 	verbose = 1;
   1712   1.91        is 	COMMAND_1ARG(argc, argv, "SITE UMASK");
   1713    1.1       cgd 	verbose = oldverbose;
   1714    1.1       cgd }
   1715    1.1       cgd 
   1716    1.4       cgd void
   1717   1.85     lukem idlecmd(int argc, char *argv[])
   1718    1.1       cgd {
   1719    1.1       cgd 	int oldverbose = verbose;
   1720    1.1       cgd 
   1721   1.80     lukem 	if (argc < 1 || argc > 2) {
   1722  1.116  christos 		UPRINTF("usage: %s [seconds]\n", argv[0]);
   1723   1.76     lukem 		code = -1;
   1724   1.76     lukem 		return;
   1725   1.76     lukem 	}
   1726    1.1       cgd 	verbose = 1;
   1727   1.91        is 	COMMAND_1ARG(argc, argv, "SITE IDLE");
   1728    1.1       cgd 	verbose = oldverbose;
   1729    1.1       cgd }
   1730    1.1       cgd 
   1731    1.1       cgd /*
   1732    1.1       cgd  * Ask the other side for help.
   1733    1.1       cgd  */
   1734    1.4       cgd void
   1735   1.85     lukem rmthelp(int argc, char *argv[])
   1736    1.1       cgd {
   1737    1.1       cgd 	int oldverbose = verbose;
   1738    1.1       cgd 
   1739   1.88     lukem 	if (argc == 0) {
   1740  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1741   1.76     lukem 		code = -1;
   1742   1.76     lukem 		return;
   1743   1.76     lukem 	}
   1744    1.1       cgd 	verbose = 1;
   1745   1.91        is 	COMMAND_1ARG(argc, argv, "HELP");
   1746    1.1       cgd 	verbose = oldverbose;
   1747    1.1       cgd }
   1748    1.1       cgd 
   1749    1.1       cgd /*
   1750    1.1       cgd  * Terminate session and exit.
   1751   1.88     lukem  * May be called with 0, NULL.
   1752    1.1       cgd  */
   1753    1.1       cgd /*VARARGS*/
   1754    1.4       cgd void
   1755   1.85     lukem quit(int argc, char *argv[])
   1756    1.1       cgd {
   1757    1.1       cgd 
   1758   1.88     lukem 			/* this may be called with argc == 0, argv == NULL */
   1759   1.76     lukem 	if (argc == 0 && argv != NULL) {
   1760  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1761   1.76     lukem 		code = -1;
   1762   1.76     lukem 		return;
   1763   1.76     lukem 	}
   1764    1.1       cgd 	if (connected)
   1765   1.76     lukem 		disconnect(0, NULL);
   1766    1.1       cgd 	pswitch(1);
   1767   1.76     lukem 	if (connected)
   1768   1.76     lukem 		disconnect(0, NULL);
   1769    1.1       cgd 	exit(0);
   1770    1.1       cgd }
   1771    1.1       cgd 
   1772    1.1       cgd /*
   1773    1.1       cgd  * Terminate session, but don't exit.
   1774   1.88     lukem  * May be called with 0, NULL.
   1775    1.1       cgd  */
   1776    1.4       cgd void
   1777   1.85     lukem disconnect(int argc, char *argv[])
   1778    1.1       cgd {
   1779    1.1       cgd 
   1780   1.88     lukem 			/* this may be called with argc == 0, argv == NULL */
   1781   1.76     lukem 	if (argc == 0 && argv != NULL) {
   1782  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   1783   1.76     lukem 		code = -1;
   1784   1.76     lukem 		return;
   1785   1.76     lukem 	}
   1786    1.1       cgd 	if (!connected)
   1787    1.1       cgd 		return;
   1788   1.19     lukem 	(void)command("QUIT");
   1789   1.76     lukem 	cleanuppeer();
   1790    1.1       cgd }
   1791    1.1       cgd 
   1792    1.4       cgd void
   1793   1.85     lukem account(int argc, char *argv[])
   1794    1.1       cgd {
   1795   1.13     lukem 	char *ap;
   1796  1.119     lukem 	char emptypass[] = "";
   1797    1.1       cgd 
   1798   1.88     lukem 	if (argc == 0 || argc > 2) {
   1799  1.116  christos 		UPRINTF("usage: %s [password]\n", argv[0]);
   1800   1.13     lukem 		code = -1;
   1801   1.13     lukem 		return;
   1802    1.1       cgd 	}
   1803   1.13     lukem 	else if (argc == 2)
   1804   1.13     lukem 		ap = argv[1];
   1805  1.119     lukem 	else {
   1806    1.1       cgd 		ap = getpass("Account:");
   1807  1.119     lukem 		if (ap == NULL)
   1808  1.119     lukem 			ap = emptypass;
   1809  1.119     lukem 	}
   1810   1.19     lukem 	(void)command("ACCT %s", ap);
   1811  1.119     lukem 	memset(ap, 0, strlen(ap));
   1812    1.1       cgd }
   1813    1.1       cgd 
   1814   1.73     lukem sigjmp_buf abortprox;
   1815    1.1       cgd 
   1816    1.1       cgd void
   1817   1.85     lukem proxabort(int notused)
   1818    1.1       cgd {
   1819    1.1       cgd 
   1820  1.106     lukem 	sigint_raised = 1;
   1821   1.18     lukem 	alarmtimer(0);
   1822    1.1       cgd 	if (!proxy) {
   1823    1.1       cgd 		pswitch(1);
   1824    1.1       cgd 	}
   1825    1.1       cgd 	if (connected) {
   1826    1.1       cgd 		proxflag = 1;
   1827    1.1       cgd 	}
   1828    1.1       cgd 	else {
   1829    1.1       cgd 		proxflag = 0;
   1830    1.1       cgd 	}
   1831    1.1       cgd 	pswitch(0);
   1832   1.72     lukem 	siglongjmp(abortprox, 1);
   1833    1.1       cgd }
   1834    1.1       cgd 
   1835    1.4       cgd void
   1836   1.85     lukem doproxy(int argc, char *argv[])
   1837    1.1       cgd {
   1838    1.4       cgd 	struct cmd *c;
   1839   1.14     lukem 	int cmdpos;
   1840   1.82     lukem 	sigfunc oldintr;
   1841    1.1       cgd 
   1842   1.88     lukem 	if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
   1843  1.116  christos 		UPRINTF("usage: %s command\n", argv[0]);
   1844    1.1       cgd 		code = -1;
   1845    1.1       cgd 		return;
   1846    1.1       cgd 	}
   1847    1.1       cgd 	c = getcmd(argv[1]);
   1848    1.1       cgd 	if (c == (struct cmd *) -1) {
   1849   1.37     lukem 		fputs("?Ambiguous command.\n", ttyout);
   1850    1.1       cgd 		code = -1;
   1851    1.1       cgd 		return;
   1852    1.1       cgd 	}
   1853    1.1       cgd 	if (c == 0) {
   1854   1.37     lukem 		fputs("?Invalid command.\n", ttyout);
   1855    1.1       cgd 		code = -1;
   1856    1.1       cgd 		return;
   1857    1.1       cgd 	}
   1858    1.1       cgd 	if (!c->c_proxy) {
   1859   1.37     lukem 		fputs("?Invalid proxy command.\n", ttyout);
   1860    1.1       cgd 		code = -1;
   1861    1.1       cgd 		return;
   1862    1.1       cgd 	}
   1863   1.72     lukem 	if (sigsetjmp(abortprox, 1)) {
   1864    1.1       cgd 		code = -1;
   1865    1.1       cgd 		return;
   1866    1.1       cgd 	}
   1867   1.62     lukem 	oldintr = xsignal(SIGINT, proxabort);
   1868    1.1       cgd 	pswitch(1);
   1869    1.1       cgd 	if (c->c_conn && !connected) {
   1870   1.37     lukem 		fputs("Not connected.\n", ttyout);
   1871    1.1       cgd 		pswitch(0);
   1872   1.62     lukem 		(void)xsignal(SIGINT, oldintr);
   1873    1.1       cgd 		code = -1;
   1874    1.1       cgd 		return;
   1875    1.1       cgd 	}
   1876   1.14     lukem 	cmdpos = strcspn(line, " \t");
   1877   1.14     lukem 	if (cmdpos > 0)		/* remove leading "proxy " from input buffer */
   1878   1.14     lukem 		memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
   1879   1.93     lukem 	argv[1] = c->c_name;
   1880    1.1       cgd 	(*c->c_handler)(argc-1, argv+1);
   1881    1.1       cgd 	if (connected) {
   1882    1.1       cgd 		proxflag = 1;
   1883    1.1       cgd 	}
   1884    1.1       cgd 	else {
   1885    1.1       cgd 		proxflag = 0;
   1886    1.1       cgd 	}
   1887    1.1       cgd 	pswitch(0);
   1888   1.62     lukem 	(void)xsignal(SIGINT, oldintr);
   1889    1.1       cgd }
   1890    1.1       cgd 
   1891    1.4       cgd void
   1892   1.85     lukem setcase(int argc, char *argv[])
   1893    1.1       cgd {
   1894    1.4       cgd 
   1895   1.10     lukem 	code = togglevar(argc, argv, &mcase, "Case mapping");
   1896    1.1       cgd }
   1897    1.1       cgd 
   1898   1.63     lukem /*
   1899   1.63     lukem  * convert the given name to lower case if it's all upper case, into
   1900   1.63     lukem  * a static buffer which is returned to the caller
   1901   1.63     lukem  */
   1902  1.110  christos static const char *
   1903  1.110  christos docase(char *dst, size_t dlen, const char *src)
   1904   1.63     lukem {
   1905  1.110  christos 	size_t i;
   1906  1.110  christos 	int dochange = 1;
   1907   1.63     lukem 
   1908  1.110  christos 	for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
   1909  1.110  christos 		dst[i] = src[i];
   1910  1.110  christos 		if (islower((unsigned char)dst[i]))
   1911   1.63     lukem 			dochange = 0;
   1912   1.63     lukem 	}
   1913  1.110  christos 	dst[i] = '\0';
   1914   1.63     lukem 
   1915   1.63     lukem 	if (dochange) {
   1916  1.110  christos 		for (i = 0; dst[i] != '\0'; i++)
   1917  1.110  christos 			if (isupper((unsigned char)dst[i]))
   1918  1.110  christos 				dst[i] = tolower((unsigned char)dst[i]);
   1919   1.63     lukem 	}
   1920  1.110  christos 	return dst;
   1921   1.63     lukem }
   1922   1.63     lukem 
   1923    1.4       cgd void
   1924   1.85     lukem setcr(int argc, char *argv[])
   1925    1.1       cgd {
   1926    1.4       cgd 
   1927   1.10     lukem 	code = togglevar(argc, argv, &crflag, "Carriage Return stripping");
   1928    1.1       cgd }
   1929    1.1       cgd 
   1930    1.4       cgd void
   1931   1.85     lukem setntrans(int argc, char *argv[])
   1932    1.1       cgd {
   1933   1.76     lukem 
   1934   1.88     lukem 	if (argc == 0 || argc > 3) {
   1935  1.116  christos 		UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
   1936   1.76     lukem 		code = -1;
   1937   1.76     lukem 		return;
   1938   1.76     lukem 	}
   1939    1.1       cgd 	if (argc == 1) {
   1940    1.1       cgd 		ntflag = 0;
   1941   1.37     lukem 		fputs("Ntrans off.\n", ttyout);
   1942    1.1       cgd 		code = ntflag;
   1943    1.1       cgd 		return;
   1944    1.1       cgd 	}
   1945    1.1       cgd 	ntflag++;
   1946    1.1       cgd 	code = ntflag;
   1947   1.63     lukem 	(void)strlcpy(ntin, argv[1], sizeof(ntin));
   1948    1.1       cgd 	if (argc == 2) {
   1949    1.1       cgd 		ntout[0] = '\0';
   1950    1.1       cgd 		return;
   1951    1.1       cgd 	}
   1952   1.63     lukem 	(void)strlcpy(ntout, argv[2], sizeof(ntout));
   1953    1.1       cgd }
   1954    1.1       cgd 
   1955  1.110  christos static const char *
   1956  1.110  christos dotrans(char *dst, size_t dlen, const char *src)
   1957    1.1       cgd {
   1958  1.110  christos 	const char *cp1;
   1959  1.110  christos 	char *cp2 = dst;
   1960  1.110  christos 	size_t i, ostop;
   1961    1.1       cgd 
   1962    1.4       cgd 	for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
   1963    1.4       cgd 		continue;
   1964  1.110  christos 	for (cp1 = src; *cp1; cp1++) {
   1965  1.110  christos 		int found = 0;
   1966    1.1       cgd 		for (i = 0; *(ntin + i) && i < 16; i++) {
   1967    1.1       cgd 			if (*cp1 == *(ntin + i)) {
   1968    1.1       cgd 				found++;
   1969    1.1       cgd 				if (i < ostop) {
   1970    1.1       cgd 					*cp2++ = *(ntout + i);
   1971  1.110  christos 					if (cp2 - dst >= dlen - 1)
   1972  1.110  christos 						goto out;
   1973    1.1       cgd 				}
   1974    1.1       cgd 				break;
   1975    1.1       cgd 			}
   1976    1.1       cgd 		}
   1977    1.1       cgd 		if (!found) {
   1978    1.1       cgd 			*cp2++ = *cp1;
   1979    1.1       cgd 		}
   1980    1.1       cgd 	}
   1981  1.110  christos out:
   1982    1.1       cgd 	*cp2 = '\0';
   1983  1.110  christos 	return dst;
   1984    1.1       cgd }
   1985    1.1       cgd 
   1986    1.4       cgd void
   1987   1.85     lukem setnmap(int argc, char *argv[])
   1988    1.1       cgd {
   1989    1.1       cgd 	char *cp;
   1990    1.1       cgd 
   1991    1.1       cgd 	if (argc == 1) {
   1992    1.1       cgd 		mapflag = 0;
   1993   1.37     lukem 		fputs("Nmap off.\n", ttyout);
   1994    1.1       cgd 		code = mapflag;
   1995    1.1       cgd 		return;
   1996    1.1       cgd 	}
   1997   1.88     lukem 	if (argc == 0 ||
   1998   1.76     lukem 	    (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
   1999  1.116  christos 		UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
   2000    1.1       cgd 		code = -1;
   2001    1.1       cgd 		return;
   2002    1.1       cgd 	}
   2003    1.1       cgd 	mapflag = 1;
   2004    1.1       cgd 	code = 1;
   2005    1.4       cgd 	cp = strchr(altarg, ' ');
   2006    1.1       cgd 	if (proxy) {
   2007    1.4       cgd 		while(*++cp == ' ')
   2008    1.4       cgd 			continue;
   2009    1.1       cgd 		altarg = cp;
   2010    1.4       cgd 		cp = strchr(altarg, ' ');
   2011    1.1       cgd 	}
   2012    1.1       cgd 	*cp = '\0';
   2013   1.63     lukem 	(void)strlcpy(mapin, altarg, MAXPATHLEN);
   2014    1.4       cgd 	while (*++cp == ' ')
   2015    1.4       cgd 		continue;
   2016   1.63     lukem 	(void)strlcpy(mapout, cp, MAXPATHLEN);
   2017    1.1       cgd }
   2018    1.1       cgd 
   2019  1.110  christos static const char *
   2020  1.110  christos domap(char *dst, size_t dlen, const char *src)
   2021    1.1       cgd {
   2022  1.110  christos 	const char *cp1 = src;
   2023  1.110  christos 	char *cp2 = mapin;
   2024  1.110  christos 	const char *tp[9], *te[9];
   2025    1.1       cgd 	int i, toks[9], toknum = 0, match = 1;
   2026    1.1       cgd 
   2027    1.1       cgd 	for (i=0; i < 9; ++i) {
   2028    1.1       cgd 		toks[i] = 0;
   2029    1.1       cgd 	}
   2030    1.1       cgd 	while (match && *cp1 && *cp2) {
   2031    1.1       cgd 		switch (*cp2) {
   2032    1.1       cgd 			case '\\':
   2033    1.1       cgd 				if (*++cp2 != *cp1) {
   2034    1.1       cgd 					match = 0;
   2035    1.1       cgd 				}
   2036    1.1       cgd 				break;
   2037    1.1       cgd 			case '$':
   2038    1.1       cgd 				if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
   2039    1.1       cgd 					if (*cp1 != *(++cp2+1)) {
   2040    1.1       cgd 						toks[toknum = *cp2 - '1']++;
   2041    1.1       cgd 						tp[toknum] = cp1;
   2042    1.1       cgd 						while (*++cp1 && *(cp2+1)
   2043    1.1       cgd 							!= *cp1);
   2044    1.1       cgd 						te[toknum] = cp1;
   2045    1.1       cgd 					}
   2046    1.1       cgd 					cp2++;
   2047    1.1       cgd 					break;
   2048    1.1       cgd 				}
   2049    1.1       cgd 				/* FALLTHROUGH */
   2050    1.1       cgd 			default:
   2051    1.1       cgd 				if (*cp2 != *cp1) {
   2052    1.1       cgd 					match = 0;
   2053    1.1       cgd 				}
   2054    1.1       cgd 				break;
   2055    1.1       cgd 		}
   2056    1.1       cgd 		if (match && *cp1) {
   2057    1.1       cgd 			cp1++;
   2058    1.1       cgd 		}
   2059    1.1       cgd 		if (match && *cp2) {
   2060    1.1       cgd 			cp2++;
   2061    1.1       cgd 		}
   2062    1.1       cgd 	}
   2063    1.1       cgd 	if (!match && *cp1) /* last token mismatch */
   2064    1.1       cgd 	{
   2065    1.1       cgd 		toks[toknum] = 0;
   2066    1.1       cgd 	}
   2067  1.110  christos 	cp2 = dst;
   2068  1.110  christos 	*cp2 = '\0';
   2069  1.110  christos 	cp1 = mapout;
   2070  1.110  christos 	while (*cp1) {
   2071    1.1       cgd 		match = 0;
   2072  1.110  christos 		switch (*cp1) {
   2073    1.1       cgd 			case '\\':
   2074  1.110  christos 				if (*(cp1 + 1)) {
   2075  1.110  christos 					*cp2++ = *++cp1;
   2076    1.1       cgd 				}
   2077    1.1       cgd 				break;
   2078    1.1       cgd 			case '[':
   2079    1.1       cgd LOOP:
   2080  1.110  christos 				if (*++cp1 == '$' &&
   2081  1.110  christos 				    isdigit((unsigned char)*(cp1+1))) {
   2082  1.110  christos 					if (*++cp1 == '0') {
   2083  1.110  christos 						const char *cp3 = src;
   2084    1.1       cgd 
   2085    1.1       cgd 						while (*cp3) {
   2086  1.110  christos 							*cp2++ = *cp3++;
   2087    1.1       cgd 						}
   2088    1.1       cgd 						match = 1;
   2089    1.1       cgd 					}
   2090  1.110  christos 					else if (toks[toknum = *cp1 - '1']) {
   2091  1.110  christos 						const char *cp3 = tp[toknum];
   2092    1.1       cgd 
   2093    1.1       cgd 						while (cp3 != te[toknum]) {
   2094  1.110  christos 							*cp2++ = *cp3++;
   2095    1.1       cgd 						}
   2096    1.1       cgd 						match = 1;
   2097    1.1       cgd 					}
   2098    1.1       cgd 				}
   2099    1.1       cgd 				else {
   2100  1.110  christos 					while (*cp1 && *cp1 != ',' &&
   2101  1.110  christos 					    *cp1 != ']') {
   2102  1.110  christos 						if (*cp1 == '\\') {
   2103  1.110  christos 							cp1++;
   2104    1.1       cgd 						}
   2105  1.110  christos 						else if (*cp1 == '$' &&
   2106  1.110  christos 						    isdigit((unsigned char)*(cp1+1))) {
   2107  1.110  christos 							if (*++cp1 == '0') {
   2108  1.110  christos 							   const char *cp3 = src;
   2109    1.1       cgd 
   2110    1.1       cgd 							   while (*cp3) {
   2111  1.110  christos 								*cp2++ = *cp3++;
   2112    1.1       cgd 							   }
   2113    1.1       cgd 							}
   2114    1.1       cgd 							else if (toks[toknum =
   2115  1.110  christos 							    *cp1 - '1']) {
   2116  1.110  christos 							   const char *cp3=tp[toknum];
   2117    1.1       cgd 
   2118    1.1       cgd 							   while (cp3 !=
   2119    1.1       cgd 								  te[toknum]) {
   2120  1.110  christos 								*cp2++ = *cp3++;
   2121    1.1       cgd 							   }
   2122    1.1       cgd 							}
   2123    1.1       cgd 						}
   2124  1.110  christos 						else if (*cp1) {
   2125  1.110  christos 							*cp2++ = *cp1++;
   2126    1.1       cgd 						}
   2127    1.1       cgd 					}
   2128  1.110  christos 					if (!*cp1) {
   2129   1.37     lukem 						fputs(
   2130   1.37     lukem 						"nmap: unbalanced brackets.\n",
   2131   1.37     lukem 						    ttyout);
   2132  1.110  christos 						return (src);
   2133    1.1       cgd 					}
   2134    1.1       cgd 					match = 1;
   2135  1.110  christos 					cp1--;
   2136    1.1       cgd 				}
   2137    1.1       cgd 				if (match) {
   2138  1.110  christos 					while (*++cp1 && *cp1 != ']') {
   2139  1.110  christos 					      if (*cp1 == '\\' && *(cp1 + 1)) {
   2140  1.110  christos 							cp1++;
   2141    1.1       cgd 					      }
   2142    1.1       cgd 					}
   2143  1.110  christos 					if (!*cp1) {
   2144   1.37     lukem 						fputs(
   2145   1.37     lukem 						"nmap: unbalanced brackets.\n",
   2146   1.37     lukem 						    ttyout);
   2147  1.110  christos 						return (src);
   2148    1.1       cgd 					}
   2149    1.1       cgd 					break;
   2150    1.1       cgd 				}
   2151  1.110  christos 				switch (*++cp1) {
   2152    1.1       cgd 					case ',':
   2153    1.1       cgd 						goto LOOP;
   2154    1.1       cgd 					case ']':
   2155    1.1       cgd 						break;
   2156    1.1       cgd 					default:
   2157  1.110  christos 						cp1--;
   2158    1.1       cgd 						goto LOOP;
   2159    1.1       cgd 				}
   2160    1.1       cgd 				break;
   2161    1.1       cgd 			case '$':
   2162  1.110  christos 				if (isdigit((unsigned char)*(cp1 + 1))) {
   2163  1.110  christos 					if (*++cp1 == '0') {
   2164  1.110  christos 						const char *cp3 = src;
   2165    1.1       cgd 
   2166    1.1       cgd 						while (*cp3) {
   2167  1.110  christos 							*cp2++ = *cp3++;
   2168    1.1       cgd 						}
   2169    1.1       cgd 					}
   2170  1.110  christos 					else if (toks[toknum = *cp1 - '1']) {
   2171  1.110  christos 						const char *cp3 = tp[toknum];
   2172    1.1       cgd 
   2173    1.1       cgd 						while (cp3 != te[toknum]) {
   2174  1.110  christos 							*cp2++ = *cp3++;
   2175    1.1       cgd 						}
   2176    1.1       cgd 					}
   2177    1.1       cgd 					break;
   2178    1.1       cgd 				}
   2179    1.1       cgd 				/* intentional drop through */
   2180    1.1       cgd 			default:
   2181  1.110  christos 				*cp2++ = *cp1;
   2182    1.1       cgd 				break;
   2183    1.1       cgd 		}
   2184  1.110  christos 		cp1++;
   2185    1.1       cgd 	}
   2186  1.110  christos 	*cp2 = '\0';
   2187  1.110  christos 	return *dst ? dst : src;
   2188    1.1       cgd }
   2189    1.1       cgd 
   2190    1.4       cgd void
   2191   1.85     lukem setpassive(int argc, char *argv[])
   2192    1.5       cgd {
   2193    1.5       cgd 
   2194   1.76     lukem 	if (argc == 1) {
   2195   1.76     lukem 		passivemode = !passivemode;
   2196   1.76     lukem 		activefallback = passivemode;
   2197   1.76     lukem 	} else if (argc != 2) {
   2198   1.76     lukem  passiveusage:
   2199  1.116  christos 		UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
   2200   1.76     lukem 		code = -1;
   2201   1.76     lukem 		return;
   2202   1.76     lukem 	} else if (strcasecmp(argv[1], "on") == 0) {
   2203   1.76     lukem 		passivemode = 1;
   2204   1.76     lukem 		activefallback = 0;
   2205   1.76     lukem 	} else if (strcasecmp(argv[1], "off") == 0) {
   2206   1.76     lukem 		passivemode = 0;
   2207   1.76     lukem 		activefallback = 0;
   2208   1.76     lukem 	} else if (strcasecmp(argv[1], "auto") == 0) {
   2209   1.76     lukem 		passivemode = 1;
   2210   1.76     lukem 		activefallback = 1;
   2211   1.76     lukem 	} else
   2212   1.76     lukem 		goto passiveusage;
   2213   1.76     lukem 	fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
   2214   1.76     lukem 	    onoff(passivemode), onoff(activefallback));
   2215   1.76     lukem 	code = passivemode;
   2216    1.5       cgd }
   2217    1.5       cgd 
   2218    1.5       cgd void
   2219   1.85     lukem setepsv4(int argc, char *argv[])
   2220   1.68     lukem {
   2221   1.68     lukem 
   2222   1.68     lukem 	code = togglevar(argc, argv, &epsv4,
   2223   1.68     lukem 	    verbose ? "EPSV/EPRT on IPv4" : NULL);
   2224   1.68     lukem 	epsv4bad = 0;
   2225   1.68     lukem }
   2226   1.68     lukem 
   2227   1.68     lukem void
   2228   1.85     lukem setsunique(int argc, char *argv[])
   2229    1.1       cgd {
   2230    1.4       cgd 
   2231   1.10     lukem 	code = togglevar(argc, argv, &sunique, "Store unique");
   2232    1.1       cgd }
   2233    1.1       cgd 
   2234    1.4       cgd void
   2235   1.85     lukem setrunique(int argc, char *argv[])
   2236    1.1       cgd {
   2237    1.4       cgd 
   2238   1.10     lukem 	code = togglevar(argc, argv, &runique, "Receive unique");
   2239    1.1       cgd }
   2240    1.1       cgd 
   2241   1.52     lukem int
   2242   1.85     lukem parserate(int argc, char *argv[], int cmdlineopt)
   2243   1.52     lukem {
   2244   1.52     lukem 	int dir, max, incr, showonly;
   2245   1.82     lukem 	sigfunc oldusr1, oldusr2;
   2246   1.52     lukem 
   2247   1.52     lukem 	if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
   2248   1.88     lukem  usage:
   2249   1.52     lukem 		if (cmdlineopt)
   2250  1.116  christos 			UPRINTF(
   2251   1.66     lukem 	"usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
   2252   1.52     lukem 			    argv[0]);
   2253   1.52     lukem 		else
   2254  1.116  christos 			UPRINTF(
   2255   1.66     lukem 	"usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
   2256   1.52     lukem 			    argv[0]);
   2257   1.52     lukem 		return -1;
   2258   1.52     lukem 	}
   2259   1.52     lukem 	dir = max = incr = showonly = 0;
   2260   1.76     lukem #define	RATE_GET	1
   2261   1.76     lukem #define	RATE_PUT	2
   2262   1.76     lukem #define	RATE_ALL	(RATE_GET | RATE_PUT)
   2263   1.52     lukem 
   2264   1.52     lukem 	if (strcasecmp(argv[1], "all") == 0)
   2265   1.52     lukem 		dir = RATE_ALL;
   2266   1.52     lukem 	else if (strcasecmp(argv[1], "get") == 0)
   2267   1.52     lukem 		dir = RATE_GET;
   2268   1.52     lukem 	else if (strcasecmp(argv[1], "put") == 0)
   2269   1.52     lukem 		dir = RATE_PUT;
   2270   1.52     lukem 	else
   2271   1.52     lukem 		goto usage;
   2272   1.52     lukem 
   2273   1.52     lukem 	if (argc >= 3) {
   2274   1.52     lukem 		if ((max = strsuftoi(argv[2])) < 0)
   2275   1.52     lukem 			goto usage;
   2276   1.52     lukem 	} else
   2277   1.52     lukem 		showonly = 1;
   2278   1.52     lukem 
   2279   1.52     lukem 	if (argc == 4) {
   2280   1.52     lukem 		if ((incr = strsuftoi(argv[3])) <= 0)
   2281   1.52     lukem 			goto usage;
   2282   1.52     lukem 	} else
   2283   1.52     lukem 		incr = DEFAULTINCR;
   2284   1.52     lukem 
   2285   1.62     lukem 	oldusr1 = xsignal(SIGUSR1, SIG_IGN);
   2286   1.62     lukem 	oldusr2 = xsignal(SIGUSR2, SIG_IGN);
   2287   1.52     lukem 	if (dir & RATE_GET) {
   2288   1.52     lukem 		if (!showonly) {
   2289   1.52     lukem 			rate_get = max;
   2290   1.52     lukem 			rate_get_incr = incr;
   2291   1.52     lukem 		}
   2292   1.52     lukem 		if (!cmdlineopt || verbose)
   2293   1.52     lukem 			fprintf(ttyout,
   2294   1.53     lukem 		"Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
   2295   1.52     lukem 			    onoff(rate_get), rate_get, rate_get_incr);
   2296   1.52     lukem 	}
   2297   1.52     lukem 	if (dir & RATE_PUT) {
   2298   1.52     lukem 		if (!showonly) {
   2299   1.52     lukem 			rate_put = max;
   2300   1.52     lukem 			rate_put_incr = incr;
   2301   1.52     lukem 		}
   2302   1.52     lukem 		if (!cmdlineopt || verbose)
   2303   1.52     lukem 			fprintf(ttyout,
   2304   1.53     lukem 		"Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
   2305   1.52     lukem 			    onoff(rate_put), rate_put, rate_put_incr);
   2306   1.52     lukem 	}
   2307   1.62     lukem 	(void)xsignal(SIGUSR1, oldusr1);
   2308   1.62     lukem 	(void)xsignal(SIGUSR2, oldusr2);
   2309   1.52     lukem 	return 0;
   2310   1.52     lukem }
   2311   1.52     lukem 
   2312   1.52     lukem void
   2313   1.85     lukem setrate(int argc, char *argv[])
   2314   1.52     lukem {
   2315   1.52     lukem 
   2316   1.52     lukem 	code = parserate(argc, argv, 0);
   2317   1.52     lukem }
   2318   1.52     lukem 
   2319   1.16     lukem /* change directory to parent directory */
   2320    1.4       cgd void
   2321   1.85     lukem cdup(int argc, char *argv[])
   2322    1.1       cgd {
   2323   1.16     lukem 	int r;
   2324    1.4       cgd 
   2325   1.88     lukem 	if (argc == 0) {
   2326  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   2327   1.76     lukem 		code = -1;
   2328   1.76     lukem 		return;
   2329   1.76     lukem 	}
   2330   1.16     lukem 	r = command("CDUP");
   2331   1.16     lukem 	if (r == ERROR && code == 500) {
   2332    1.1       cgd 		if (verbose)
   2333   1.37     lukem 			fputs("CDUP command not recognized, trying XCUP.\n",
   2334   1.37     lukem 			    ttyout);
   2335   1.16     lukem 		r = command("XCUP");
   2336    1.1       cgd 	}
   2337   1.79     lukem 	if (r == COMPLETE) {
   2338   1.16     lukem 		dirchange = 1;
   2339  1.109     lukem 		updateremotecwd();
   2340   1.79     lukem 	}
   2341    1.1       cgd }
   2342    1.1       cgd 
   2343   1.27     lukem /*
   2344   1.27     lukem  * Restart transfer at specific point
   2345   1.27     lukem  */
   2346    1.4       cgd void
   2347   1.85     lukem restart(int argc, char *argv[])
   2348    1.1       cgd {
   2349    1.4       cgd 
   2350   1.88     lukem 	if (argc == 0 || argc > 2) {
   2351  1.116  christos 		UPRINTF("usage: %s [restart-point]\n", argv[0]);
   2352   1.31     lukem 		code = -1;
   2353   1.31     lukem 		return;
   2354   1.31     lukem 	}
   2355   1.88     lukem 	if (! features[FEAT_REST_STREAM]) {
   2356   1.88     lukem 		fprintf(ttyout,
   2357   1.88     lukem 		    "Restart is not supported by the remote server.\n");
   2358   1.88     lukem 		return;
   2359   1.88     lukem 	}
   2360   1.31     lukem 	if (argc == 2) {
   2361   1.60     lukem 		off_t rp;
   2362   1.31     lukem 		char *ep;
   2363   1.31     lukem 
   2364   1.89     lukem 		rp = STRTOLL(argv[1], &ep, 10);
   2365   1.31     lukem 		if (rp < 0 || *ep != '\0')
   2366   1.37     lukem 			fprintf(ttyout, "restart: Invalid offset `%s'\n",
   2367   1.37     lukem 			    argv[1]);
   2368   1.31     lukem 		else
   2369   1.31     lukem 			restart_point = rp;
   2370    1.1       cgd 	}
   2371   1.31     lukem 	if (restart_point == 0)
   2372   1.37     lukem 		fputs("No restart point defined.\n", ttyout);
   2373   1.31     lukem 	else
   2374   1.37     lukem 		fprintf(ttyout,
   2375   1.90     lukem 		    "Restarting at " LLF " for next get, put or append\n",
   2376   1.90     lukem 		    (LLT)restart_point);
   2377    1.1       cgd }
   2378    1.1       cgd 
   2379   1.47     lukem /*
   2380   1.27     lukem  * Show remote system type
   2381   1.27     lukem  */
   2382    1.4       cgd void
   2383   1.85     lukem syst(int argc, char *argv[])
   2384    1.1       cgd {
   2385   1.88     lukem 	int oldverbose = verbose;
   2386    1.4       cgd 
   2387   1.88     lukem 	if (argc == 0) {
   2388  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   2389   1.76     lukem 		code = -1;
   2390   1.76     lukem 		return;
   2391   1.76     lukem 	}
   2392   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2393   1.19     lukem 	(void)command("SYST");
   2394   1.88     lukem 	verbose = oldverbose;
   2395    1.1       cgd }
   2396    1.1       cgd 
   2397    1.4       cgd void
   2398   1.85     lukem macdef(int argc, char *argv[])
   2399    1.1       cgd {
   2400    1.1       cgd 	char *tmp;
   2401    1.1       cgd 	int c;
   2402    1.1       cgd 
   2403   1.88     lukem 	if (argc == 0)
   2404   1.76     lukem 		goto usage;
   2405    1.1       cgd 	if (macnum == 16) {
   2406   1.37     lukem 		fputs("Limit of 16 macros have already been defined.\n",
   2407   1.37     lukem 		    ttyout);
   2408    1.1       cgd 		code = -1;
   2409    1.1       cgd 		return;
   2410    1.1       cgd 	}
   2411   1.10     lukem 	if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
   2412   1.76     lukem  usage:
   2413  1.116  christos 		UPRINTF("usage: %s macro_name\n", argv[0]);
   2414    1.1       cgd 		code = -1;
   2415    1.1       cgd 		return;
   2416    1.1       cgd 	}
   2417   1.19     lukem 	if (interactive)
   2418   1.37     lukem 		fputs(
   2419   1.37     lukem 		"Enter macro line by line, terminating it with a null line.\n",
   2420   1.37     lukem 		    ttyout);
   2421   1.63     lukem 	(void)strlcpy(macros[macnum].mac_name, argv[1],
   2422   1.63     lukem 	    sizeof(macros[macnum].mac_name));
   2423   1.19     lukem 	if (macnum == 0)
   2424    1.1       cgd 		macros[macnum].mac_start = macbuf;
   2425   1.19     lukem 	else
   2426    1.1       cgd 		macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
   2427    1.1       cgd 	tmp = macros[macnum].mac_start;
   2428    1.1       cgd 	while (tmp != macbuf+4096) {
   2429    1.1       cgd 		if ((c = getchar()) == EOF) {
   2430   1.37     lukem 			fputs("macdef: end of file encountered.\n", ttyout);
   2431    1.1       cgd 			code = -1;
   2432    1.1       cgd 			return;
   2433    1.1       cgd 		}
   2434    1.1       cgd 		if ((*tmp = c) == '\n') {
   2435    1.1       cgd 			if (tmp == macros[macnum].mac_start) {
   2436    1.1       cgd 				macros[macnum++].mac_end = tmp;
   2437    1.1       cgd 				code = 0;
   2438    1.1       cgd 				return;
   2439    1.1       cgd 			}
   2440    1.1       cgd 			if (*(tmp-1) == '\0') {
   2441    1.1       cgd 				macros[macnum++].mac_end = tmp - 1;
   2442    1.1       cgd 				code = 0;
   2443    1.1       cgd 				return;
   2444    1.1       cgd 			}
   2445    1.1       cgd 			*tmp = '\0';
   2446    1.1       cgd 		}
   2447    1.1       cgd 		tmp++;
   2448    1.1       cgd 	}
   2449    1.1       cgd 	while (1) {
   2450    1.1       cgd 		while ((c = getchar()) != '\n' && c != EOF)
   2451    1.1       cgd 			/* LOOP */;
   2452    1.1       cgd 		if (c == EOF || getchar() == '\n') {
   2453   1.37     lukem 			fputs("Macro not defined - 4K buffer exceeded.\n",
   2454   1.37     lukem 			    ttyout);
   2455    1.1       cgd 			code = -1;
   2456    1.1       cgd 			return;
   2457    1.1       cgd 		}
   2458    1.1       cgd 	}
   2459    1.1       cgd }
   2460    1.1       cgd 
   2461    1.1       cgd /*
   2462   1.27     lukem  * Get size of file on remote machine
   2463    1.1       cgd  */
   2464    1.4       cgd void
   2465   1.85     lukem sizecmd(int argc, char *argv[])
   2466    1.1       cgd {
   2467   1.11     lukem 	off_t size;
   2468    1.1       cgd 
   2469   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2470   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   2471  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   2472    1.1       cgd 		code = -1;
   2473    1.1       cgd 		return;
   2474    1.1       cgd 	}
   2475   1.13     lukem 	size = remotesize(argv[1], 1);
   2476   1.11     lukem 	if (size != -1)
   2477   1.37     lukem 		fprintf(ttyout,
   2478   1.90     lukem 		    "%s\t" LLF "\n", argv[1], (LLT)size);
   2479   1.76     lukem 	code = (size > 0);
   2480   1.10     lukem }
   2481   1.10     lukem 
   2482   1.10     lukem /*
   2483   1.27     lukem  * Get last modification time of file on remote machine
   2484   1.10     lukem  */
   2485   1.10     lukem void
   2486   1.85     lukem modtime(int argc, char *argv[])
   2487   1.10     lukem {
   2488   1.10     lukem 	time_t mtime;
   2489   1.10     lukem 
   2490   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2491   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   2492  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   2493   1.10     lukem 		code = -1;
   2494   1.10     lukem 		return;
   2495   1.10     lukem 	}
   2496   1.13     lukem 	mtime = remotemodtime(argv[1], 1);
   2497   1.10     lukem 	if (mtime != -1)
   2498  1.123     lukem 		fprintf(ttyout, "%s\t%s", argv[1],
   2499  1.123     lukem 		    rfc2822time(localtime(&mtime)));
   2500   1.76     lukem 	code = (mtime > 0);
   2501    1.1       cgd }
   2502    1.1       cgd 
   2503    1.1       cgd /*
   2504   1.27     lukem  * Show status on remote machine
   2505    1.1       cgd  */
   2506    1.4       cgd void
   2507   1.85     lukem rmtstatus(int argc, char *argv[])
   2508    1.1       cgd {
   2509    1.4       cgd 
   2510   1.88     lukem 	if (argc == 0) {
   2511  1.116  christos 		UPRINTF("usage: %s [remote-file]\n", argv[0]);
   2512   1.76     lukem 		code = -1;
   2513   1.76     lukem 		return;
   2514   1.76     lukem 	}
   2515   1.91        is 	COMMAND_1ARG(argc, argv, "STAT");
   2516    1.1       cgd }
   2517    1.1       cgd 
   2518    1.1       cgd /*
   2519   1.27     lukem  * Get file if modtime is more recent than current file
   2520    1.1       cgd  */
   2521    1.4       cgd void
   2522   1.85     lukem newer(int argc, char *argv[])
   2523    1.1       cgd {
   2524    1.4       cgd 
   2525    1.1       cgd 	if (getit(argc, argv, -1, "w"))
   2526   1.37     lukem 		fprintf(ttyout,
   2527   1.37     lukem 		    "Local file \"%s\" is newer than remote file \"%s\".\n",
   2528   1.37     lukem 		    argv[2], argv[1]);
   2529   1.19     lukem }
   2530   1.19     lukem 
   2531   1.19     lukem /*
   2532   1.76     lukem  * Display one local file through $PAGER.
   2533   1.19     lukem  */
   2534   1.19     lukem void
   2535   1.85     lukem lpage(int argc, char *argv[])
   2536   1.19     lukem {
   2537  1.114     lukem 	size_t len;
   2538   1.63     lukem 	char *p, *pager, *locfile;
   2539   1.19     lukem 
   2540   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2541   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "local-file"))) {
   2542  1.116  christos 		UPRINTF("usage: %s local-file\n", argv[0]);
   2543   1.19     lukem 		code = -1;
   2544   1.19     lukem 		return;
   2545   1.19     lukem 	}
   2546   1.63     lukem 	if ((locfile = globulize(argv[1])) == NULL) {
   2547   1.63     lukem 		code = -1;
   2548   1.63     lukem 		return;
   2549   1.63     lukem 	}
   2550   1.76     lukem 	p = getoptionvalue("pager");
   2551   1.76     lukem 	if (EMPTYSTRING(p))
   2552   1.76     lukem 		p = DEFAULTPAGER;
   2553   1.63     lukem 	len = strlen(p) + strlen(locfile) + 2;
   2554  1.117  christos 	pager = ftp_malloc(len);
   2555   1.63     lukem 	(void)strlcpy(pager, p,		len);
   2556   1.63     lukem 	(void)strlcat(pager, " ",	len);
   2557   1.63     lukem 	(void)strlcat(pager, locfile,	len);
   2558   1.63     lukem 	system(pager);
   2559   1.76     lukem 	code = 0;
   2560   1.63     lukem 	(void)free(pager);
   2561   1.63     lukem 	(void)free(locfile);
   2562   1.63     lukem }
   2563   1.63     lukem 
   2564   1.63     lukem /*
   2565   1.76     lukem  * Display one remote file through $PAGER.
   2566   1.63     lukem  */
   2567   1.63     lukem void
   2568   1.85     lukem page(int argc, char *argv[])
   2569   1.63     lukem {
   2570  1.114     lukem 	int ohash, orestart_point, overbose;
   2571  1.114     lukem 	size_t len;
   2572   1.63     lukem 	char *p, *pager;
   2573   1.63     lukem 
   2574   1.88     lukem 	if (argc == 0 || argc > 2 ||
   2575   1.88     lukem 	    (argc == 1 && !another(&argc, &argv, "remote-file"))) {
   2576  1.116  christos 		UPRINTF("usage: %s remote-file\n", argv[0]);
   2577   1.19     lukem 		code = -1;
   2578   1.19     lukem 		return;
   2579   1.19     lukem 	}
   2580   1.76     lukem 	p = getoptionvalue("pager");
   2581   1.76     lukem 	if (EMPTYSTRING(p))
   2582   1.76     lukem 		p = DEFAULTPAGER;
   2583   1.49     lukem 	len = strlen(p) + 2;
   2584  1.117  christos 	pager = ftp_malloc(len);
   2585   1.57     lukem 	pager[0] = '|';
   2586   1.63     lukem 	(void)strlcpy(pager + 1, p, len - 1);
   2587   1.19     lukem 
   2588   1.19     lukem 	ohash = hash;
   2589   1.37     lukem 	orestart_point = restart_point;
   2590   1.19     lukem 	overbose = verbose;
   2591   1.37     lukem 	hash = restart_point = verbose = 0;
   2592   1.97     lukem 	recvrequest("RETR", pager, argv[1], "r+", 1, 0);
   2593   1.19     lukem 	hash = ohash;
   2594   1.37     lukem 	restart_point = orestart_point;
   2595   1.19     lukem 	verbose = overbose;
   2596   1.63     lukem 	(void)free(pager);
   2597   1.39   thorpej }
   2598   1.39   thorpej 
   2599   1.39   thorpej /*
   2600   1.58     lukem  * Set the socket send or receive buffer size.
   2601   1.39   thorpej  */
   2602   1.39   thorpej void
   2603   1.85     lukem setxferbuf(int argc, char *argv[])
   2604   1.39   thorpej {
   2605   1.58     lukem 	int size, dir;
   2606   1.39   thorpej 
   2607   1.39   thorpej 	if (argc != 2) {
   2608   1.58     lukem  usage:
   2609  1.116  christos 		UPRINTF("usage: %s size\n", argv[0]);
   2610   1.39   thorpej 		code = -1;
   2611   1.39   thorpej 		return;
   2612   1.39   thorpej 	}
   2613   1.58     lukem 	if (strcasecmp(argv[0], "sndbuf") == 0)
   2614   1.58     lukem 		dir = RATE_PUT;
   2615   1.58     lukem 	else if (strcasecmp(argv[0], "rcvbuf") == 0)
   2616   1.58     lukem 		dir = RATE_GET;
   2617   1.58     lukem 	else if (strcasecmp(argv[0], "xferbuf") == 0)
   2618   1.58     lukem 		dir = RATE_ALL;
   2619   1.39   thorpej 	else
   2620   1.58     lukem 		goto usage;
   2621   1.39   thorpej 
   2622   1.58     lukem 	if ((size = strsuftoi(argv[1])) == -1)
   2623   1.58     lukem 		goto usage;
   2624   1.39   thorpej 
   2625   1.58     lukem 	if (size == 0) {
   2626   1.58     lukem 		fprintf(ttyout, "%s: size must be positive.\n", argv[0]);
   2627   1.58     lukem 		goto usage;
   2628   1.39   thorpej 	}
   2629   1.39   thorpej 
   2630   1.58     lukem 	if (dir & RATE_PUT)
   2631   1.58     lukem 		sndbuf_size = size;
   2632   1.58     lukem 	if (dir & RATE_GET)
   2633   1.58     lukem 		rcvbuf_size = size;
   2634   1.58     lukem 	fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
   2635   1.58     lukem 	    sndbuf_size, rcvbuf_size);
   2636   1.76     lukem 	code = 0;
   2637   1.76     lukem }
   2638   1.76     lukem 
   2639   1.76     lukem /*
   2640   1.76     lukem  * Set or display options (defaults are provided by various env vars)
   2641   1.76     lukem  */
   2642   1.76     lukem void
   2643   1.85     lukem setoption(int argc, char *argv[])
   2644   1.76     lukem {
   2645   1.76     lukem 	struct option *o;
   2646   1.76     lukem 
   2647   1.76     lukem 	code = -1;
   2648   1.88     lukem 	if (argc == 0 || (argc != 1 && argc != 3)) {
   2649  1.116  christos 		UPRINTF("usage: %s [option value]\n", argv[0]);
   2650   1.76     lukem 		return;
   2651   1.76     lukem 	}
   2652   1.76     lukem 
   2653   1.76     lukem #define	OPTIONINDENT ((int) sizeof("http_proxy"))
   2654   1.76     lukem 	if (argc == 1) {
   2655   1.76     lukem 		for (o = optiontab; o->name != NULL; o++) {
   2656   1.76     lukem 			fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT,
   2657   1.76     lukem 			    o->name, o->value ? o->value : "");
   2658   1.76     lukem 		}
   2659   1.76     lukem 	} else {
   2660   1.76     lukem 		o = getoption(argv[1]);
   2661   1.76     lukem 		if (o == NULL) {
   2662   1.76     lukem 			fprintf(ttyout, "No such option `%s'.\n", argv[1]);
   2663   1.76     lukem 			return;
   2664   1.76     lukem 		}
   2665   1.76     lukem 		FREEPTR(o->value);
   2666  1.117  christos 		o->value = ftp_strdup(argv[2]);
   2667   1.76     lukem 		if (verbose)
   2668   1.76     lukem 			fprintf(ttyout, "Setting `%s' to `%s'.\n",
   2669   1.76     lukem 			    o->name, o->value);
   2670   1.76     lukem 	}
   2671   1.76     lukem 	code = 0;
   2672   1.76     lukem }
   2673   1.76     lukem 
   2674   1.76     lukem /*
   2675   1.76     lukem  * Unset an option
   2676   1.76     lukem  */
   2677   1.76     lukem void
   2678   1.85     lukem unsetoption(int argc, char *argv[])
   2679   1.76     lukem {
   2680   1.76     lukem 	struct option *o;
   2681   1.76     lukem 
   2682   1.76     lukem 	code = -1;
   2683   1.88     lukem 	if (argc == 0 || argc != 2) {
   2684  1.116  christos 		UPRINTF("usage: %s option\n", argv[0]);
   2685   1.76     lukem 		return;
   2686   1.76     lukem 	}
   2687   1.76     lukem 
   2688   1.76     lukem 	o = getoption(argv[1]);
   2689   1.76     lukem 	if (o == NULL) {
   2690   1.76     lukem 		fprintf(ttyout, "No such option `%s'.\n", argv[1]);
   2691   1.76     lukem 		return;
   2692   1.76     lukem 	}
   2693   1.76     lukem 	FREEPTR(o->value);
   2694   1.76     lukem 	fprintf(ttyout, "Unsetting `%s'.\n", o->name);
   2695   1.76     lukem 	code = 0;
   2696   1.88     lukem }
   2697   1.88     lukem 
   2698   1.88     lukem /*
   2699   1.88     lukem  * Display features supported by the remote host.
   2700   1.88     lukem  */
   2701   1.88     lukem void
   2702   1.88     lukem feat(int argc, char *argv[])
   2703   1.88     lukem {
   2704   1.88     lukem 	int oldverbose = verbose;
   2705   1.88     lukem 
   2706   1.88     lukem 	if (argc == 0) {
   2707  1.116  christos 		UPRINTF("usage: %s\n", argv[0]);
   2708   1.88     lukem 		code = -1;
   2709   1.88     lukem 		return;
   2710   1.88     lukem 	}
   2711   1.88     lukem 	if (! features[FEAT_FEAT]) {
   2712   1.88     lukem 		fprintf(ttyout,
   2713   1.88     lukem 		    "FEAT is not supported by the remote server.\n");
   2714   1.88     lukem 		return;
   2715   1.88     lukem 	}
   2716   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2717   1.88     lukem 	(void)command("FEAT");
   2718   1.88     lukem 	verbose = oldverbose;
   2719   1.88     lukem }
   2720   1.88     lukem 
   2721   1.88     lukem void
   2722   1.88     lukem mlst(int argc, char *argv[])
   2723   1.88     lukem {
   2724   1.88     lukem 	int oldverbose = verbose;
   2725   1.88     lukem 
   2726   1.88     lukem 	if (argc < 1 || argc > 2) {
   2727  1.116  christos 		UPRINTF("usage: %s [remote-path]\n", argv[0]);
   2728   1.88     lukem 		code = -1;
   2729   1.88     lukem 		return;
   2730   1.88     lukem 	}
   2731   1.88     lukem 	if (! features[FEAT_MLST]) {
   2732   1.88     lukem 		fprintf(ttyout,
   2733   1.88     lukem 		    "MLST is not supported by the remote server.\n");
   2734   1.88     lukem 		return;
   2735   1.88     lukem 	}
   2736   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2737   1.91        is 	COMMAND_1ARG(argc, argv, "MLST");
   2738   1.88     lukem 	verbose = oldverbose;
   2739   1.88     lukem }
   2740   1.88     lukem 
   2741   1.88     lukem void
   2742   1.88     lukem opts(int argc, char *argv[])
   2743   1.88     lukem {
   2744   1.88     lukem 	int oldverbose = verbose;
   2745   1.88     lukem 
   2746   1.88     lukem 	if (argc < 2 || argc > 3) {
   2747  1.116  christos 		UPRINTF("usage: %s command [options]\n", argv[0]);
   2748   1.88     lukem 		code = -1;
   2749   1.88     lukem 		return;
   2750   1.88     lukem 	}
   2751   1.88     lukem 	if (! features[FEAT_FEAT]) {
   2752   1.88     lukem 		fprintf(ttyout,
   2753   1.88     lukem 		    "OPTS is not supported by the remote server.\n");
   2754   1.88     lukem 		return;
   2755   1.88     lukem 	}
   2756   1.88     lukem 	verbose = 1;	/* If we aren't verbose, this doesn't do anything! */
   2757   1.91        is 	if (argc == 2)
   2758   1.91        is 		command("OPTS %s", argv[1]);
   2759   1.91        is 	else
   2760   1.91        is 		command("OPTS %s %s", argv[1], argv[2]);
   2761   1.88     lukem 	verbose = oldverbose;
   2762    1.1       cgd }
   2763