1 /* $NetBSD: cmds.c,v 1.123 2007/05/24 05:05:18 lukem Exp $ */
4 * Copyright (c) 1996-2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
12 * NASA Ames Research Center.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the NetBSD
25 * Foundation, Inc. and its contributors.
26 * 4. Neither the name of The NetBSD Foundation nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
44 * Copyright (c) 1985, 1989, 1993, 1994
45 * The Regents of the University of California. All rights reserved.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * Copyright (C) 1997 and 1998 WIDE Project.
74 * All rights reserved.
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
79 * 1. Redistributions of source code must retain the above copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. Neither the name of the project nor the names of its contributors
85 * may be used to endorse or promote products derived from this software
86 * without specific prior written permission.
88 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
89 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
90 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
91 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
92 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
93 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
94 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
95 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
96 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
97 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 #include <sys/cdefs.h>
104 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
106 __RCSID("$NetBSD: cmds.c,v 1.123 2007/05/24 05:05:18 lukem Exp $");
108 #endif /* not lint */
111 * FTP User Program -- Command Routines.
113 #include <sys/types.h>
114 #include <sys/socket.h>
115 #include <sys/stat.h>
116 #include <sys/wait.h>
117 #include <arpa/ftp.h>
134 static struct types {
140 { "ascii", "A", TYPE_A, 0 },
141 { "binary", "I", TYPE_I, 0 },
142 { "image", "I", TYPE_I, 0 },
143 { "ebcdic", "E", TYPE_E, 0 },
144 { "tenex", "L", TYPE_L, bytename },
148 static sigjmp_buf jabort;
150 static int confirm(const char *, const char *);
151 static void mintr(int);
152 static void mabort(const char *);
154 static const char *doprocess(char *, size_t, const char *, int, int, int);
155 static const char *domap(char *, size_t, const char *);
156 static const char *docase(char *, size_t, const char *);
157 static const char *dotrans(char *, size_t, const char *);
160 * Confirm if "cmd" is to be performed upon "file".
161 * If "file" is NULL, generate a "Continue with" prompt instead.
164 confirm(const char *cmd, const char *file)
166 const char *errormsg;
168 const char *promptleft, *promptright;
170 if (!interactive || confirmrest)
173 promptleft = "Continue with";
180 fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright);
181 (void)fflush(ttyout);
182 if (getline(stdin, line, sizeof(line), &errormsg) < 0) {
184 fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd);
187 switch (tolower((unsigned char)*line)) {
191 "Prompting off for duration of %s.\n", cmd);
195 fputs("Interactive mode: off.\n", ttyout);
199 fprintf(ttyout, "%s aborted.\n", cmd);
205 " confirmation options:\n"
206 "\ta answer `yes' for the duration of %s\n"
207 "\tn answer `no' for this file\n"
208 "\tp turn off `prompt' mode\n"
209 "\tq stop the current %s\n"
210 "\ty answer `yes' for this file\n"
211 "\t? this help list\n",
213 continue; /* back to while(1) */
224 settype(int argc, char *argv[])
229 if (argc == 0 || argc > 2) {
232 UPRINTF("usage: %s [", argv[0]);
234 for (p = types; p->t_name; p++) {
235 fprintf(ttyout, "%s%s", sep, p->t_name);
238 fputs(" ]\n", ttyout);
243 fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
247 for (p = types; p->t_name; p++)
248 if (strcmp(argv[1], p->t_name) == 0)
250 if (p->t_name == 0) {
251 fprintf(ttyout, "%s: unknown mode.\n", argv[1]);
255 if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
256 comret = command("TYPE %s %s", p->t_mode, p->t_arg);
258 comret = command("TYPE %s", p->t_mode);
259 if (comret == COMPLETE) {
260 (void)strlcpy(typename, p->t_name, sizeof(typename));
261 curtype = type = p->t_type;
266 * Internal form of settype; changes current type in use with server
267 * without changing our notion of the type for data transfers.
268 * Used to change to and from ascii for listings.
271 changetype(int newtype, int show)
274 int comret, oldverbose = verbose;
278 if (newtype == curtype)
280 if (ftp_debug == 0 && show == 0)
282 for (p = types; p->t_name; p++)
283 if (newtype == p->t_type)
285 if (p->t_name == 0) {
286 errx(1, "changetype: unknown type %d", newtype);
288 if (newtype == TYPE_L && bytename[0] != '\0')
289 comret = command("TYPE %s %s", p->t_mode, bytename);
291 comret = command("TYPE %s", p->t_mode);
292 if (comret == COMPLETE)
294 verbose = oldverbose;
304 * Set binary transfer type.
308 setbinary(int argc, char *argv[])
312 UPRINTF("usage: %s\n", argv[0]);
321 * Set ascii transfer type.
325 setascii(int argc, char *argv[])
329 UPRINTF("usage: %s\n", argv[0]);
338 * Set tenex transfer type.
342 settenex(int argc, char *argv[])
346 UPRINTF("usage: %s\n", argv[0]);
355 * Set file transfer mode.
359 setftmode(int argc, char *argv[])
363 UPRINTF("usage: %s mode-name\n", argv[0]);
367 fprintf(ttyout, "We only support %s mode, sorry.\n", modename);
372 * Set file transfer format.
376 setform(int argc, char *argv[])
380 UPRINTF("usage: %s format\n", argv[0]);
384 fprintf(ttyout, "We only support %s format, sorry.\n", formname);
389 * Set file transfer structure.
393 setstruct(int argc, char *argv[])
397 UPRINTF("usage: %s struct-mode\n", argv[0]);
401 fprintf(ttyout, "We only support %s structure, sorry.\n", structname);
406 * Send a single file.
409 put(int argc, char *argv[])
411 char buf[MAXPATHLEN];
422 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file")))
424 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
426 UPRINTF("usage: %s local-file [remote-file]\n", argv[0]);
430 if ((locfile = globulize(argv[1])) == NULL) {
435 if (loc) /* If argv[2] is a copy of the old argv[1], update it */
437 cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
438 remfile = doprocess(buf, sizeof(buf), remfile,
439 0, loc && ntflag, loc && mapflag);
440 sendrequest(cmd, locfile, remfile,
441 locfile != argv[1] || remfile != argv[2]);
446 doprocess(char *dst, size_t dlen, const char *src,
447 int casef, int transf, int mapf)
450 src = docase(dst, dlen, src);
452 src = dotrans(dst, dlen, src);
454 src = domap(dst, dlen, src);
459 * Send multiple files.
462 mput(int argc, char *argv[])
469 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
470 UPRINTF("usage: %s local-files\n", argv[0]);
475 oldintr = xsignal(SIGINT, mintr);
476 if (sigsetjmp(jabort, 1))
481 while ((cp = remglob(argv, 0, NULL)) != NULL) {
482 if (*cp == '\0' || !connected) {
486 if (mflag && confirm(argv[0], cp)) {
487 char buf[MAXPATHLEN];
488 tp = doprocess(buf, sizeof(buf), cp,
489 mcase, ntflag, mapflag);
490 sendrequest((sunique) ? "STOU" : "STOR",
491 cp, tp, cp != tp || !interactive);
492 if (!mflag && fromatty) {
493 ointer = interactive;
495 if (confirm(argv[0], NULL)) {
498 interactive = ointer;
504 for (i = 1; i < argc && connected; i++) {
510 if (mflag && confirm(argv[0], argv[i])) {
511 char buf[MAXPATHLEN];
512 tp = doprocess(buf, sizeof(buf), argv[i],
514 sendrequest((sunique) ? "STOU" : "STOR",
515 argv[i], tp, tp != argv[i] || !interactive);
516 if (!mflag && fromatty) {
517 ointer = interactive;
519 if (confirm(argv[0], NULL)) {
522 interactive = ointer;
528 memset(&gl, 0, sizeof(gl));
529 flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
530 if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
531 warnx("Glob pattern `%s' not found", argv[i]);
535 for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
537 if (mflag && confirm(argv[0], *cpp)) {
538 char buf[MAXPATHLEN];
540 tp = doprocess(buf, sizeof(buf), *cpp,
542 sendrequest((sunique) ? "STOU" : "STOR",
543 *cpp, tp, *cpp != tp || !interactive);
544 if (!mflag && fromatty) {
545 ointer = interactive;
547 if (confirm(argv[0], NULL)) {
550 interactive = ointer;
557 (void)xsignal(SIGINT, oldintr);
562 reget(int argc, char *argv[])
565 (void)getit(argc, argv, 1, "r+");
569 get(int argc, char *argv[])
572 (void)getit(argc, argv, 0, restart_point ? "r+" : "w" );
577 * If restartit is 1, restart the xfer always.
578 * If restartit is -1, restart the xfer only if the remote file is newer.
581 getit(int argc, char *argv[], int restartit, const char *mode)
584 char *remfile, *olocfile;
586 char buf[MAXPATHLEN];
594 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file")))
596 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
598 UPRINTF("usage: %s remote-file [local-file]\n", argv[0]);
603 if ((olocfile = globulize(argv[2])) == NULL) {
607 locfile = doprocess(buf, sizeof(buf), olocfile,
608 loc && mcase, loc && ntflag, loc && mapflag);
613 if (! features[FEAT_REST_STREAM]) {
615 "Restart is not supported by the remote server.\n");
618 ret = stat(locfile, &stbuf);
619 if (restartit == 1) {
621 warn("Can't stat `%s'", locfile);
624 restart_point = stbuf.st_size;
629 mtime = remotemodtime(argv[1], 0);
632 if (stbuf.st_mtime >= mtime) {
640 recvrequest("RETR", locfile, remfile, mode,
641 remfile != argv[1] || locfile != argv[2], loc);
644 (void)free(olocfile);
655 write(fileno(ttyout), "\n", 1);
656 siglongjmp(jabort, 1);
660 mabort(const char *cmd)
664 if (mflag && fromatty) {
665 ointer = interactive;
669 if (confirm(cmd, NULL)) {
670 interactive = ointer;
674 interactive = ointer;
681 * Get multiple files.
684 mget(int argc, char *argv[])
693 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
694 UPRINTF("usage: %s remote-files\n", argv[0]);
701 if (strcmp(argv[0], "mreget") == 0) {
702 if (! features[FEAT_REST_STREAM]) {
704 "Restart is not supported by the remote server.\n");
709 oldintr = xsignal(SIGINT, mintr);
710 if (sigsetjmp(jabort, 1))
712 while ((cp = remglob(argv, proxy, NULL)) != NULL) {
713 char buf[MAXPATHLEN];
714 if (*cp == '\0' || !connected) {
720 if (! fileindir(cp, localcwd)) {
721 fprintf(ttyout, "Skipping non-relative filename `%s'\n",
725 if (!confirm(argv[0], cp))
727 tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag);
731 if (stat(tp, &stbuf) == 0)
732 restart_point = stbuf.st_size;
734 warn("Can't stat `%s'", tp);
736 recvrequest("RETR", tp, cp, restart_point ? "r+" : "w",
737 tp != cp || !interactive, 1);
739 if (!mflag && fromatty) {
740 ointer = interactive;
742 if (confirm(argv[0], NULL))
744 interactive = ointer;
747 (void)xsignal(SIGINT, oldintr);
752 * Read list of filenames from a local file and get those
755 fget(int argc, char *argv[])
759 char buf[MAXPATHLEN];
762 UPRINTF("usage: %s localfile\n", argv[0]);
767 fp = fopen(argv[1], "r");
769 fprintf(ttyout, "Can't open source file %s\n", argv[1]);
775 mode = restart_point ? "r+" : "w";
777 while (getline(fp, buf, sizeof(buf), NULL) >= 0) {
781 (void)getit(argc, argv, 0, mode);
790 return (bool ? "on" : "off");
798 status(int argc, char *argv[])
802 UPRINTF("usage: %s\n", argv[0]);
808 fprintf(ttyout, "Connected %sto %s.\n",
809 connected == -1 ? "and logged in" : "", hostname);
811 fputs("Not connected.\n", ttyout);
815 fprintf(ttyout, "Connected for proxy commands to %s.\n",
819 fputs("No proxy connection.\n", ttyout);
823 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
824 *gateserver ? gateserver : "(none)", gateport);
825 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
826 onoff(passivemode), onoff(activefallback));
827 fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
828 modename, typename, formname, structname);
829 fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
830 onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob));
831 fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n",
832 onoff(sunique), onoff(runique));
833 fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve));
834 fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase),
837 fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout);
840 fputs("Ntrans: off.\n", ttyout);
843 fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout);
846 fputs("Nmap: off.\n", ttyout);
849 "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
850 onoff(hash), mark, onoff(progress));
852 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
853 onoff(rate_get), rate_get, rate_get_incr);
855 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
856 onoff(rate_put), rate_put, rate_put_incr);
858 "Socket buffer sizes: send %d, receive %d.\n",
859 sndbuf_size, rcvbuf_size);
860 fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
861 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
862 epsv4bad ? " (disabled for this connection)" : "");
863 fprintf(ttyout, "Command line editing: %s.\n",
864 #ifdef NO_EDITCOMPLETE
865 "support not compiled in"
866 #else /* !def NO_EDITCOMPLETE */
868 #endif /* !def NO_EDITCOMPLETE */
873 fputs("Macros:\n", ttyout);
874 for (i=0; i<macnum; i++) {
875 fprintf(ttyout, "\t%s\n", macros[i].mac_name);
878 #endif /* !def NO_STATUS */
879 fprintf(ttyout, "Version: %s %s\n", FTP_PRODUCT, FTP_VERSION);
887 togglevar(int argc, char *argv[], int *var, const char *mesg)
891 } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
893 } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
896 UPRINTF("usage: %s [ on | off ]\n", argv[0]);
900 fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
905 * Set beep on cmd completed mode.
909 setbell(int argc, char *argv[])
912 code = togglevar(argc, argv, &bell, "Bell mode");
916 * Set command line editing
920 setedit(int argc, char *argv[])
923 #ifdef NO_EDITCOMPLETE
925 UPRINTF("usage: %s\n", argv[0]);
930 fputs("Editing support not compiled in; ignoring command.\n",
932 #else /* !def NO_EDITCOMPLETE */
933 code = togglevar(argc, argv, &editing, "Editing mode");
935 #endif /* !def NO_EDITCOMPLETE */
939 * Turn on packet tracing.
943 settrace(int argc, char *argv[])
946 code = togglevar(argc, argv, &trace, "Packet tracing");
950 * Toggle hash mark printing during transfers, or set hash mark bytecount.
954 sethash(int argc, char *argv[])
958 else if (argc != 2) {
959 UPRINTF("usage: %s [ on | off | bytecount ]\n",
963 } else if (strcasecmp(argv[1], "on") == 0)
965 else if (strcasecmp(argv[1], "off") == 0)
970 nmark = strsuftoi(argv[1]);
972 fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
980 fprintf(ttyout, "Hash mark printing %s", onoff(hash));
982 fprintf(ttyout, " (%d bytes/hash mark)", mark);
983 fputs(".\n", ttyout);
990 * Turn on printing of server echo's.
994 setverbose(int argc, char *argv[])
997 code = togglevar(argc, argv, &verbose, "Verbose mode");
1001 * Toggle PORT/LPRT cmd use before each data connection.
1005 setport(int argc, char *argv[])
1008 code = togglevar(argc, argv, &sendport, "Use of PORT/LPRT cmds");
1012 * Toggle transfer progress bar.
1016 setprogress(int argc, char *argv[])
1019 code = togglevar(argc, argv, &progress, "Progress bar");
1025 * Turn on interactive prompting during mget, mput, and mdelete.
1029 setprompt(int argc, char *argv[])
1032 code = togglevar(argc, argv, &interactive, "Interactive mode");
1036 * Toggle gate-ftp mode, or set gate-ftp server
1040 setgate(int argc, char *argv[])
1042 static char gsbuf[MAXHOSTNAMELEN];
1044 if (argc == 0 || argc > 3) {
1046 "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
1049 } else if (argc < 2) {
1050 gatemode = !gatemode;
1052 if (argc == 2 && strcasecmp(argv[1], "on") == 0)
1054 else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
1058 gateport = ftp_strdup(argv[2]);
1059 (void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
1064 if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
1066 "Disabling gate-ftp mode - no gate-ftp server defined.\n");
1069 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n",
1070 onoff(gatemode), *gateserver ? gateserver : "(none)",
1077 * Toggle metacharacter interpretation on local file names.
1081 setglob(int argc, char *argv[])
1084 code = togglevar(argc, argv, &doglob, "Globbing");
1088 * Toggle preserving modification times on retrieved files.
1092 setpreserve(int argc, char *argv[])
1095 code = togglevar(argc, argv, &preserve, "Preserve modification times");
1099 * Set debugging mode on/off and/or set level of debugging.
1103 setdebug(int argc, char *argv[])
1105 if (argc == 0 || argc > 2) {
1106 UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
1109 } else if (argc == 2) {
1110 if (strcasecmp(argv[1], "on") == 0)
1112 else if (strcasecmp(argv[1], "off") == 0)
1117 val = strsuftoi(argv[1]);
1119 fprintf(ttyout, "%s: bad debugging value.\n",
1127 ftp_debug = !ftp_debug;
1129 options |= SO_DEBUG;
1131 options &= ~SO_DEBUG;
1132 fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
1133 code = ftp_debug > 0;
1137 * Set current working directory on remote machine.
1140 cd(int argc, char *argv[])
1144 if (argc == 0 || argc > 2 ||
1145 (argc == 1 && !another(&argc, &argv, "remote-directory"))) {
1146 UPRINTF("usage: %s remote-directory\n", argv[0]);
1150 r = command("CWD %s", argv[1]);
1151 if (r == ERROR && code == 500) {
1153 fputs("CWD command not recognized, trying XCWD.\n",
1155 r = command("XCWD %s", argv[1]);
1157 if (r == COMPLETE) {
1164 * Set current working directory on local machine.
1167 lcd(int argc, char *argv[])
1174 argv[1] = localhome;
1177 UPRINTF("usage: %s [local-directory]\n", argv[0]);
1180 if ((locdir = globulize(argv[1])) == NULL)
1182 if (chdir(locdir) == -1)
1183 warn("Can't chdir `%s'", locdir);
1187 fprintf(ttyout, "Local directory now: %s\n", localcwd);
1190 fprintf(ttyout, "Unable to determine local directory\n");
1197 * Delete a single file.
1200 delete(int argc, char *argv[])
1203 if (argc == 0 || argc > 2 ||
1204 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
1205 UPRINTF("usage: %s remote-file\n", argv[0]);
1209 if (command("DELE %s", argv[1]) == COMPLETE)
1214 * Delete multiple files.
1217 mdelete(int argc, char *argv[])
1224 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
1225 UPRINTF("usage: %s [remote-files]\n", argv[0]);
1230 oldintr = xsignal(SIGINT, mintr);
1231 if (sigsetjmp(jabort, 1))
1233 while ((cp = remglob(argv, 0, NULL)) != NULL) {
1238 if (mflag && confirm(argv[0], cp)) {
1239 if (command("DELE %s", cp) == COMPLETE)
1241 if (!mflag && fromatty) {
1242 ointer = interactive;
1244 if (confirm(argv[0], NULL)) {
1247 interactive = ointer;
1251 (void)xsignal(SIGINT, oldintr);
1256 * Rename a remote file.
1259 renamefile(int argc, char *argv[])
1262 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name")))
1264 if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
1266 UPRINTF("usage: %s from-name to-name\n", argv[0]);
1270 if (command("RNFR %s", argv[1]) == CONTINUE &&
1271 command("RNTO %s", argv[2]) == COMPLETE)
1276 * Get a directory listing of remote files.
1277 * Supports being invoked as:
1283 * pdir, pls LIST |$PAGER
1284 * mmlsd MLSD |$PAGER
1287 ls(int argc, char *argv[])
1290 char *remdir, *locfile;
1291 int freelocfile, pagecmd, mlsdcmd;
1295 freelocfile = pagecmd = mlsdcmd = 0;
1297 * the only commands that start with `p' are
1298 * the `pager' versions.
1300 if (argv[0][0] == 'p')
1302 if (strcmp(argv[0] + pagecmd , "mlsd") == 0) {
1303 if (! features[FEAT_MLST]) {
1305 "MLSD is not supported by the remote server.\n");
1315 else if (strcmp(argv[0] + pagecmd, "nlist") == 0)
1324 if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
1326 if (pagecmd || mlsdcmd)
1327 UPRINTF("usage: %s [remote-path]\n", argv[0]);
1329 UPRINTF("usage: %s [remote-path [local-file]]\n",
1339 p = getoptionvalue("pager");
1342 len = strlen(p) + 2;
1343 locfile = ftp_malloc(len);
1345 (void)strlcpy(locfile + 1, p, len - 1);
1347 } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
1348 if ((locfile = globulize(locfile)) == NULL ||
1349 !confirm("output to local-file:", locfile)) {
1355 recvrequest(cmd, locfile, remdir, "w", 0, 0);
1357 if (freelocfile && locfile)
1358 (void)free(locfile);
1362 * Get a directory listing of multiple remote files.
1365 mls(int argc, char *argv[])
1370 char *mode, *dest, *odest;
1374 if (argc < 2 && !another(&argc, &argv, "remote-files"))
1376 if (argc < 3 && !another(&argc, &argv, "local-file")) {
1378 UPRINTF("usage: %s remote-files local-file\n", argv[0]);
1382 odest = dest = argv[argc - 1];
1383 argv[argc - 1] = NULL;
1384 if (strcmp(dest, "-") && *dest != '|')
1385 if (((dest = globulize(dest)) == NULL) ||
1386 !confirm("output to local-file:", dest)) {
1390 dolist = strcmp(argv[0], "mls");
1392 oldintr = xsignal(SIGINT, mintr);
1393 if (sigsetjmp(jabort, 1))
1395 for (i = 1; mflag && i < argc-1 && connected; i++) {
1396 mode = (i == 1) ? "w" : "a";
1397 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
1399 if (!mflag && fromatty) {
1400 ointer = interactive;
1402 if (confirm(argv[0], NULL)) {
1405 interactive = ointer;
1408 (void)xsignal(SIGINT, oldintr);
1410 if (dest != odest) /* free up after globulize() */
1419 shell(int argc, char *argv[])
1423 char shellnam[MAXPATHLEN], *shell, *namep;
1427 UPRINTF("usage: %s [command [args]]\n", argv[0]);
1431 oldintr = xsignal(SIGINT, SIG_IGN);
1432 if ((pid = fork()) == 0) {
1433 for (pid = 3; pid < 20; pid++)
1435 (void)xsignal(SIGINT, SIG_DFL);
1436 shell = getenv("SHELL");
1438 shell = _PATH_BSHELL;
1439 namep = strrchr(shell, '/');
1444 (void)strlcpy(shellnam, namep, sizeof(shellnam));
1446 fputs(shell, ttyout);
1450 execl(shell, shellnam, "-c", altarg, (char *)0);
1453 execl(shell, shellnam, (char *)0);
1455 warn("Can't execute `%s'", shell);
1460 while (wait(&wait_status) != pid)
1462 (void)xsignal(SIGINT, oldintr);
1464 warn("Can't fork a subshell; try again later");
1471 * Send new user information (re-login)
1474 user(int argc, char *argv[])
1477 char emptypass[] = "";
1483 (void)another(&argc, &argv, "username");
1484 if (argc < 2 || argc > 4) {
1486 UPRINTF("usage: %s username [password [account]]\n",
1491 n = command("USER %s", argv[1]);
1492 if (n == CONTINUE) {
1494 password = getpass("Password: ");
1495 if (password == NULL)
1496 password = emptypass;
1500 n = command("PASS %s", password);
1501 memset(password, 0, strlen(password));
1503 if (n == CONTINUE) {
1506 password = getpass("Account: ");
1507 if (password == NULL)
1508 password = emptypass;
1512 n = command("ACCT %s", password);
1513 memset(password, 0, strlen(password));
1515 if (n != COMPLETE) {
1516 fputs("Login failed.\n", ttyout);
1519 if (!aflag && argc == 4) {
1521 (void)command("ACCT %s", password);
1522 memset(password, 0, strlen(password));
1529 * Print working directory on remote machine.
1533 pwd(int argc, char *argv[])
1538 UPRINTF("usage: %s\n", argv[0]);
1544 fprintf(ttyout, "Unable to determine remote directory\n");
1546 fprintf(ttyout, "Remote directory: %s\n", remotecwd);
1552 * Print working directory on local machine.
1555 lpwd(int argc, char *argv[])
1560 UPRINTF("usage: %s\n", argv[0]);
1566 fprintf(ttyout, "Unable to determine local directory\n");
1568 fprintf(ttyout, "Local directory: %s\n", localcwd);
1577 makedir(int argc, char *argv[])
1581 if (argc == 0 || argc > 2 ||
1582 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1583 UPRINTF("usage: %s directory-name\n", argv[0]);
1587 r = command("MKD %s", argv[1]);
1588 if (r == ERROR && code == 500) {
1590 fputs("MKD command not recognized, trying XMKD.\n",
1592 r = command("XMKD %s", argv[1]);
1599 * Remove a directory.
1602 removedir(int argc, char *argv[])
1606 if (argc == 0 || argc > 2 ||
1607 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1608 UPRINTF("usage: %s directory-name\n", argv[0]);
1612 r = command("RMD %s", argv[1]);
1613 if (r == ERROR && code == 500) {
1615 fputs("RMD command not recognized, trying XRMD.\n",
1617 r = command("XRMD %s", argv[1]);
1624 * Send a line, verbatim, to the remote machine.
1627 quote(int argc, char *argv[])
1631 (argc == 1 && !another(&argc, &argv, "command line to send"))) {
1632 UPRINTF("usage: %s line-to-send\n", argv[0]);
1636 quote1("", argc, argv);
1640 * Send a SITE command to the remote machine. The line
1641 * is sent verbatim to the remote machine, except that the
1642 * word "SITE" is added at the front.
1645 site(int argc, char *argv[])
1649 (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
1650 UPRINTF("usage: %s line-to-send\n", argv[0]);
1654 quote1("SITE ", argc, argv);
1658 * Turn argv[1..argc) into a space-separated string, then prepend initial text.
1659 * Send the result as a one-line command and get response.
1662 quote1(const char *initial, int argc, char *argv[])
1665 char buf[BUFSIZ]; /* must be >= sizeof(line) */
1667 (void)strlcpy(buf, initial, sizeof(buf));
1668 for (i = 1; i < argc; i++) {
1669 (void)strlcat(buf, argv[i], sizeof(buf));
1671 (void)strlcat(buf, " ", sizeof(buf));
1673 if (command("%s", buf) == PRELIM) {
1674 while (getreply(0) == PRELIM)
1681 do_chmod(int argc, char *argv[])
1684 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode")))
1686 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
1688 UPRINTF("usage: %s mode remote-file\n", argv[0]);
1692 (void)command("SITE CHMOD %s %s", argv[1], argv[2]);
1695 #define COMMAND_1ARG(argc, argv, cmd) \
1699 command(cmd " %s", argv[1])
1702 do_umask(int argc, char *argv[])
1704 int oldverbose = verbose;
1707 UPRINTF("usage: %s [umask]\n", argv[0]);
1712 COMMAND_1ARG(argc, argv, "SITE UMASK");
1713 verbose = oldverbose;
1717 idlecmd(int argc, char *argv[])
1719 int oldverbose = verbose;
1721 if (argc < 1 || argc > 2) {
1722 UPRINTF("usage: %s [seconds]\n", argv[0]);
1727 COMMAND_1ARG(argc, argv, "SITE IDLE");
1728 verbose = oldverbose;
1732 * Ask the other side for help.
1735 rmthelp(int argc, char *argv[])
1737 int oldverbose = verbose;
1740 UPRINTF("usage: %s\n", argv[0]);
1745 COMMAND_1ARG(argc, argv, "HELP");
1746 verbose = oldverbose;
1750 * Terminate session and exit.
1751 * May be called with 0, NULL.
1755 quit(int argc, char *argv[])
1758 /* this may be called with argc == 0, argv == NULL */
1759 if (argc == 0 && argv != NULL) {
1760 UPRINTF("usage: %s\n", argv[0]);
1765 disconnect(0, NULL);
1768 disconnect(0, NULL);
1773 * Terminate session, but don't exit.
1774 * May be called with 0, NULL.
1777 disconnect(int argc, char *argv[])
1780 /* this may be called with argc == 0, argv == NULL */
1781 if (argc == 0 && argv != NULL) {
1782 UPRINTF("usage: %s\n", argv[0]);
1788 (void)command("QUIT");
1793 account(int argc, char *argv[])
1796 char emptypass[] = "";
1798 if (argc == 0 || argc > 2) {
1799 UPRINTF("usage: %s [password]\n", argv[0]);
1806 ap = getpass("Account:");
1810 (void)command("ACCT %s", ap);
1811 memset(ap, 0, strlen(ap));
1814 sigjmp_buf abortprox;
1817 proxabort(int notused)
1832 siglongjmp(abortprox, 1);
1836 doproxy(int argc, char *argv[])
1842 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
1843 UPRINTF("usage: %s command\n", argv[0]);
1847 c = getcmd(argv[1]);
1848 if (c == (struct cmd *) -1) {
1849 fputs("?Ambiguous command.\n", ttyout);
1854 fputs("?Invalid command.\n", ttyout);
1859 fputs("?Invalid proxy command.\n", ttyout);
1863 if (sigsetjmp(abortprox, 1)) {
1867 oldintr = xsignal(SIGINT, proxabort);
1869 if (c->c_conn && !connected) {
1870 fputs("Not connected.\n", ttyout);
1872 (void)xsignal(SIGINT, oldintr);
1876 cmdpos = strcspn(line, " \t");
1877 if (cmdpos > 0) /* remove leading "proxy " from input buffer */
1878 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
1879 argv[1] = c->c_name;
1880 (*c->c_handler)(argc-1, argv+1);
1888 (void)xsignal(SIGINT, oldintr);
1892 setcase(int argc, char *argv[])
1895 code = togglevar(argc, argv, &mcase, "Case mapping");
1899 * convert the given name to lower case if it's all upper case, into
1900 * a static buffer which is returned to the caller
1903 docase(char *dst, size_t dlen, const char *src)
1908 for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
1910 if (islower((unsigned char)dst[i]))
1916 for (i = 0; dst[i] != '\0'; i++)
1917 if (isupper((unsigned char)dst[i]))
1918 dst[i] = tolower((unsigned char)dst[i]);
1924 setcr(int argc, char *argv[])
1927 code = togglevar(argc, argv, &crflag, "Carriage Return stripping");
1931 setntrans(int argc, char *argv[])
1934 if (argc == 0 || argc > 3) {
1935 UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
1941 fputs("Ntrans off.\n", ttyout);
1947 (void)strlcpy(ntin, argv[1], sizeof(ntin));
1952 (void)strlcpy(ntout, argv[2], sizeof(ntout));
1956 dotrans(char *dst, size_t dlen, const char *src)
1962 for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
1964 for (cp1 = src; *cp1; cp1++) {
1966 for (i = 0; *(ntin + i) && i < 16; i++) {
1967 if (*cp1 == *(ntin + i)) {
1970 *cp2++ = *(ntout + i);
1971 if (cp2 - dst >= dlen - 1)
1987 setnmap(int argc, char *argv[])
1993 fputs("Nmap off.\n", ttyout);
1998 (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
1999 UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
2005 cp = strchr(altarg, ' ');
2010 cp = strchr(altarg, ' ');
2013 (void)strlcpy(mapin, altarg, MAXPATHLEN);
2014 while (*++cp == ' ')
2016 (void)strlcpy(mapout, cp, MAXPATHLEN);
2020 domap(char *dst, size_t dlen, const char *src)
2022 const char *cp1 = src;
2024 const char *tp[9], *te[9];
2025 int i, toks[9], toknum = 0, match = 1;
2027 for (i=0; i < 9; ++i) {
2030 while (match && *cp1 && *cp2) {
2033 if (*++cp2 != *cp1) {
2038 if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
2039 if (*cp1 != *(++cp2+1)) {
2040 toks[toknum = *cp2 - '1']++;
2042 while (*++cp1 && *(cp2+1)
2056 if (match && *cp1) {
2059 if (match && *cp2) {
2063 if (!match && *cp1) /* last token mismatch */
2080 if (*++cp1 == '$' &&
2081 isdigit((unsigned char)*(cp1+1))) {
2082 if (*++cp1 == '0') {
2083 const char *cp3 = src;
2090 else if (toks[toknum = *cp1 - '1']) {
2091 const char *cp3 = tp[toknum];
2093 while (cp3 != te[toknum]) {
2100 while (*cp1 && *cp1 != ',' &&
2105 else if (*cp1 == '$' &&
2106 isdigit((unsigned char)*(cp1+1))) {
2107 if (*++cp1 == '0') {
2108 const char *cp3 = src;
2114 else if (toks[toknum =
2116 const char *cp3=tp[toknum];
2130 "nmap: unbalanced brackets.\n",
2138 while (*++cp1 && *cp1 != ']') {
2139 if (*cp1 == '\\' && *(cp1 + 1)) {
2145 "nmap: unbalanced brackets.\n",
2162 if (isdigit((unsigned char)*(cp1 + 1))) {
2163 if (*++cp1 == '0') {
2164 const char *cp3 = src;
2170 else if (toks[toknum = *cp1 - '1']) {
2171 const char *cp3 = tp[toknum];
2173 while (cp3 != te[toknum]) {
2179 /* intentional drop through */
2187 return *dst ? dst : src;
2191 setpassive(int argc, char *argv[])
2195 passivemode = !passivemode;
2196 activefallback = passivemode;
2197 } else if (argc != 2) {
2199 UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
2202 } else if (strcasecmp(argv[1], "on") == 0) {
2205 } else if (strcasecmp(argv[1], "off") == 0) {
2208 } else if (strcasecmp(argv[1], "auto") == 0) {
2213 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
2214 onoff(passivemode), onoff(activefallback));
2219 setepsv4(int argc, char *argv[])
2222 code = togglevar(argc, argv, &epsv4,
2223 verbose ? "EPSV/EPRT on IPv4" : NULL);
2228 setsunique(int argc, char *argv[])
2231 code = togglevar(argc, argv, &sunique, "Store unique");
2235 setrunique(int argc, char *argv[])
2238 code = togglevar(argc, argv, &runique, "Receive unique");
2242 parserate(int argc, char *argv[], int cmdlineopt)
2244 int dir, max, incr, showonly;
2245 sigfunc oldusr1, oldusr2;
2247 if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
2251 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
2255 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
2259 dir = max = incr = showonly = 0;
2262 #define RATE_ALL (RATE_GET | RATE_PUT)
2264 if (strcasecmp(argv[1], "all") == 0)
2266 else if (strcasecmp(argv[1], "get") == 0)
2268 else if (strcasecmp(argv[1], "put") == 0)
2274 if ((max = strsuftoi(argv[2])) < 0)
2280 if ((incr = strsuftoi(argv[3])) <= 0)
2285 oldusr1 = xsignal(SIGUSR1, SIG_IGN);
2286 oldusr2 = xsignal(SIGUSR2, SIG_IGN);
2287 if (dir & RATE_GET) {
2290 rate_get_incr = incr;
2292 if (!cmdlineopt || verbose)
2294 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
2295 onoff(rate_get), rate_get, rate_get_incr);
2297 if (dir & RATE_PUT) {
2300 rate_put_incr = incr;
2302 if (!cmdlineopt || verbose)
2304 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
2305 onoff(rate_put), rate_put, rate_put_incr);
2307 (void)xsignal(SIGUSR1, oldusr1);
2308 (void)xsignal(SIGUSR2, oldusr2);
2313 setrate(int argc, char *argv[])
2316 code = parserate(argc, argv, 0);
2319 /* change directory to parent directory */
2321 cdup(int argc, char *argv[])
2326 UPRINTF("usage: %s\n", argv[0]);
2330 r = command("CDUP");
2331 if (r == ERROR && code == 500) {
2333 fputs("CDUP command not recognized, trying XCUP.\n",
2335 r = command("XCUP");
2337 if (r == COMPLETE) {
2344 * Restart transfer at specific point
2347 restart(int argc, char *argv[])
2350 if (argc == 0 || argc > 2) {
2351 UPRINTF("usage: %s [restart-point]\n", argv[0]);
2355 if (! features[FEAT_REST_STREAM]) {
2357 "Restart is not supported by the remote server.\n");
2364 rp = STRTOLL(argv[1], &ep, 10);
2365 if (rp < 0 || *ep != '\0')
2366 fprintf(ttyout, "restart: Invalid offset `%s'\n",
2371 if (restart_point == 0)
2372 fputs("No restart point defined.\n", ttyout);
2375 "Restarting at " LLF " for next get, put or append\n",
2376 (LLT)restart_point);
2380 * Show remote system type
2383 syst(int argc, char *argv[])
2385 int oldverbose = verbose;
2388 UPRINTF("usage: %s\n", argv[0]);
2392 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2393 (void)command("SYST");
2394 verbose = oldverbose;
2398 macdef(int argc, char *argv[])
2406 fputs("Limit of 16 macros have already been defined.\n",
2411 if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
2413 UPRINTF("usage: %s macro_name\n", argv[0]);
2419 "Enter macro line by line, terminating it with a null line.\n",
2421 (void)strlcpy(macros[macnum].mac_name, argv[1],
2422 sizeof(macros[macnum].mac_name));
2424 macros[macnum].mac_start = macbuf;
2426 macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
2427 tmp = macros[macnum].mac_start;
2428 while (tmp != macbuf+4096) {
2429 if ((c = getchar()) == EOF) {
2430 fputs("macdef: end of file encountered.\n", ttyout);
2434 if ((*tmp = c) == '\n') {
2435 if (tmp == macros[macnum].mac_start) {
2436 macros[macnum++].mac_end = tmp;
2440 if (*(tmp-1) == '\0') {
2441 macros[macnum++].mac_end = tmp - 1;
2450 while ((c = getchar()) != '\n' && c != EOF)
2452 if (c == EOF || getchar() == '\n') {
2453 fputs("Macro not defined - 4K buffer exceeded.\n",
2462 * Get size of file on remote machine
2465 sizecmd(int argc, char *argv[])
2469 if (argc == 0 || argc > 2 ||
2470 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2471 UPRINTF("usage: %s remote-file\n", argv[0]);
2475 size = remotesize(argv[1], 1);
2478 "%s\t" LLF "\n", argv[1], (LLT)size);
2483 * Get last modification time of file on remote machine
2486 modtime(int argc, char *argv[])
2490 if (argc == 0 || argc > 2 ||
2491 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2492 UPRINTF("usage: %s remote-file\n", argv[0]);
2496 mtime = remotemodtime(argv[1], 1);
2498 fprintf(ttyout, "%s\t%s", argv[1],
2499 rfc2822time(localtime(&mtime)));
2504 * Show status on remote machine
2507 rmtstatus(int argc, char *argv[])
2511 UPRINTF("usage: %s [remote-file]\n", argv[0]);
2515 COMMAND_1ARG(argc, argv, "STAT");
2519 * Get file if modtime is more recent than current file
2522 newer(int argc, char *argv[])
2525 if (getit(argc, argv, -1, "w"))
2527 "Local file \"%s\" is newer than remote file \"%s\".\n",
2532 * Display one local file through $PAGER.
2535 lpage(int argc, char *argv[])
2538 char *p, *pager, *locfile;
2540 if (argc == 0 || argc > 2 ||
2541 (argc == 1 && !another(&argc, &argv, "local-file"))) {
2542 UPRINTF("usage: %s local-file\n", argv[0]);
2546 if ((locfile = globulize(argv[1])) == NULL) {
2550 p = getoptionvalue("pager");
2553 len = strlen(p) + strlen(locfile) + 2;
2554 pager = ftp_malloc(len);
2555 (void)strlcpy(pager, p, len);
2556 (void)strlcat(pager, " ", len);
2557 (void)strlcat(pager, locfile, len);
2561 (void)free(locfile);
2565 * Display one remote file through $PAGER.
2568 page(int argc, char *argv[])
2570 int ohash, orestart_point, overbose;
2574 if (argc == 0 || argc > 2 ||
2575 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2576 UPRINTF("usage: %s remote-file\n", argv[0]);
2580 p = getoptionvalue("pager");
2583 len = strlen(p) + 2;
2584 pager = ftp_malloc(len);
2586 (void)strlcpy(pager + 1, p, len - 1);
2589 orestart_point = restart_point;
2591 hash = restart_point = verbose = 0;
2592 recvrequest("RETR", pager, argv[1], "r+", 1, 0);
2594 restart_point = orestart_point;
2600 * Set the socket send or receive buffer size.
2603 setxferbuf(int argc, char *argv[])
2609 UPRINTF("usage: %s size\n", argv[0]);
2613 if (strcasecmp(argv[0], "sndbuf") == 0)
2615 else if (strcasecmp(argv[0], "rcvbuf") == 0)
2617 else if (strcasecmp(argv[0], "xferbuf") == 0)
2622 if ((size = strsuftoi(argv[1])) == -1)
2626 fprintf(ttyout, "%s: size must be positive.\n", argv[0]);
2634 fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
2635 sndbuf_size, rcvbuf_size);
2640 * Set or display options (defaults are provided by various env vars)
2643 setoption(int argc, char *argv[])
2648 if (argc == 0 || (argc != 1 && argc != 3)) {
2649 UPRINTF("usage: %s [option value]\n", argv[0]);
2653 #define OPTIONINDENT ((int) sizeof("http_proxy"))
2655 for (o = optiontab; o->name != NULL; o++) {
2656 fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT,
2657 o->name, o->value ? o->value : "");
2660 o = getoption(argv[1]);
2662 fprintf(ttyout, "No such option `%s'.\n", argv[1]);
2666 o->value = ftp_strdup(argv[2]);
2668 fprintf(ttyout, "Setting `%s' to `%s'.\n",
2678 unsetoption(int argc, char *argv[])
2683 if (argc == 0 || argc != 2) {
2684 UPRINTF("usage: %s option\n", argv[0]);
2688 o = getoption(argv[1]);
2690 fprintf(ttyout, "No such option `%s'.\n", argv[1]);
2694 fprintf(ttyout, "Unsetting `%s'.\n", o->name);
2699 * Display features supported by the remote host.
2702 feat(int argc, char *argv[])
2704 int oldverbose = verbose;
2707 UPRINTF("usage: %s\n", argv[0]);
2711 if (! features[FEAT_FEAT]) {
2713 "FEAT is not supported by the remote server.\n");
2716 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2717 (void)command("FEAT");
2718 verbose = oldverbose;
2722 mlst(int argc, char *argv[])
2724 int oldverbose = verbose;
2726 if (argc < 1 || argc > 2) {
2727 UPRINTF("usage: %s [remote-path]\n", argv[0]);
2731 if (! features[FEAT_MLST]) {
2733 "MLST is not supported by the remote server.\n");
2736 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2737 COMMAND_1ARG(argc, argv, "MLST");
2738 verbose = oldverbose;
2742 opts(int argc, char *argv[])
2744 int oldverbose = verbose;
2746 if (argc < 2 || argc > 3) {
2747 UPRINTF("usage: %s command [options]\n", argv[0]);
2751 if (! features[FEAT_FEAT]) {
2753 "OPTS is not supported by the remote server.\n");
2756 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2758 command("OPTS %s", argv[1]);
2760 command("OPTS %s %s", argv[1], argv[2]);
2761 verbose = oldverbose;