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