1 /* $NetBSD: cmds.c,v 1.121 2007/04/18 01:39:04 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.121 2007/04/18 01:39:04 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[])
761 UPRINTF("usage: %s localfile\n", argv[0]);
766 fp = fopen(argv[1], "r");
768 fprintf(ttyout, "Can't open source file %s\n", argv[1]);
774 mode = restart_point ? "r+" : "w";
777 (buf = fparseln(fp, NULL, NULL, "\0\0\0", 0)) != NULL;
782 (void)getit(argc, argv, 0, mode);
791 return (bool ? "on" : "off");
799 status(int argc, char *argv[])
803 UPRINTF("usage: %s\n", argv[0]);
809 fprintf(ttyout, "Connected %sto %s.\n",
810 connected == -1 ? "and logged in" : "", hostname);
812 fputs("Not connected.\n", ttyout);
816 fprintf(ttyout, "Connected for proxy commands to %s.\n",
820 fputs("No proxy connection.\n", ttyout);
824 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
825 *gateserver ? gateserver : "(none)", gateport);
826 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
827 onoff(passivemode), onoff(activefallback));
828 fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
829 modename, typename, formname, structname);
830 fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
831 onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob));
832 fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n",
833 onoff(sunique), onoff(runique));
834 fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve));
835 fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase),
838 fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout);
841 fputs("Ntrans: off.\n", ttyout);
844 fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout);
847 fputs("Nmap: off.\n", ttyout);
850 "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
851 onoff(hash), mark, onoff(progress));
853 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
854 onoff(rate_get), rate_get, rate_get_incr);
856 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
857 onoff(rate_put), rate_put, rate_put_incr);
859 "Socket buffer sizes: send %d, receive %d.\n",
860 sndbuf_size, rcvbuf_size);
861 fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
862 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
863 epsv4bad ? " (disabled for this connection)" : "");
864 fprintf(ttyout, "Command line editing: %s.\n",
865 #ifdef NO_EDITCOMPLETE
866 "support not compiled in"
867 #else /* !def NO_EDITCOMPLETE */
869 #endif /* !def NO_EDITCOMPLETE */
874 fputs("Macros:\n", ttyout);
875 for (i=0; i<macnum; i++) {
876 fprintf(ttyout, "\t%s\n", macros[i].mac_name);
879 #endif /* !def NO_STATUS */
880 fprintf(ttyout, "Version: %s %s\n", FTP_PRODUCT, FTP_VERSION);
888 togglevar(int argc, char *argv[], int *var, const char *mesg)
892 } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
894 } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
897 UPRINTF("usage: %s [ on | off ]\n", argv[0]);
901 fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
906 * Set beep on cmd completed mode.
910 setbell(int argc, char *argv[])
913 code = togglevar(argc, argv, &bell, "Bell mode");
917 * Set command line editing
921 setedit(int argc, char *argv[])
924 #ifdef NO_EDITCOMPLETE
926 UPRINTF("usage: %s\n", argv[0]);
931 fputs("Editing support not compiled in; ignoring command.\n",
933 #else /* !def NO_EDITCOMPLETE */
934 code = togglevar(argc, argv, &editing, "Editing mode");
936 #endif /* !def NO_EDITCOMPLETE */
940 * Turn on packet tracing.
944 settrace(int argc, char *argv[])
947 code = togglevar(argc, argv, &trace, "Packet tracing");
951 * Toggle hash mark printing during transfers, or set hash mark bytecount.
955 sethash(int argc, char *argv[])
959 else if (argc != 2) {
960 UPRINTF("usage: %s [ on | off | bytecount ]\n",
964 } else if (strcasecmp(argv[1], "on") == 0)
966 else if (strcasecmp(argv[1], "off") == 0)
971 nmark = strsuftoi(argv[1]);
973 fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
981 fprintf(ttyout, "Hash mark printing %s", onoff(hash));
983 fprintf(ttyout, " (%d bytes/hash mark)", mark);
984 fputs(".\n", ttyout);
991 * Turn on printing of server echo's.
995 setverbose(int argc, char *argv[])
998 code = togglevar(argc, argv, &verbose, "Verbose mode");
1002 * Toggle PORT/LPRT cmd use before each data connection.
1006 setport(int argc, char *argv[])
1009 code = togglevar(argc, argv, &sendport, "Use of PORT/LPRT cmds");
1013 * Toggle transfer progress bar.
1017 setprogress(int argc, char *argv[])
1020 code = togglevar(argc, argv, &progress, "Progress bar");
1026 * Turn on interactive prompting during mget, mput, and mdelete.
1030 setprompt(int argc, char *argv[])
1033 code = togglevar(argc, argv, &interactive, "Interactive mode");
1037 * Toggle gate-ftp mode, or set gate-ftp server
1041 setgate(int argc, char *argv[])
1043 static char gsbuf[MAXHOSTNAMELEN];
1045 if (argc == 0 || argc > 3) {
1047 "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
1050 } else if (argc < 2) {
1051 gatemode = !gatemode;
1053 if (argc == 2 && strcasecmp(argv[1], "on") == 0)
1055 else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
1059 gateport = ftp_strdup(argv[2]);
1060 (void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
1065 if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
1067 "Disabling gate-ftp mode - no gate-ftp server defined.\n");
1070 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n",
1071 onoff(gatemode), *gateserver ? gateserver : "(none)",
1078 * Toggle metacharacter interpretation on local file names.
1082 setglob(int argc, char *argv[])
1085 code = togglevar(argc, argv, &doglob, "Globbing");
1089 * Toggle preserving modification times on retrieved files.
1093 setpreserve(int argc, char *argv[])
1096 code = togglevar(argc, argv, &preserve, "Preserve modification times");
1100 * Set debugging mode on/off and/or set level of debugging.
1104 setdebug(int argc, char *argv[])
1106 if (argc == 0 || argc > 2) {
1107 UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
1110 } else if (argc == 2) {
1111 if (strcasecmp(argv[1], "on") == 0)
1113 else if (strcasecmp(argv[1], "off") == 0)
1118 val = strsuftoi(argv[1]);
1120 fprintf(ttyout, "%s: bad debugging value.\n",
1128 ftp_debug = !ftp_debug;
1130 options |= SO_DEBUG;
1132 options &= ~SO_DEBUG;
1133 fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
1134 code = ftp_debug > 0;
1138 * Set current working directory on remote machine.
1141 cd(int argc, char *argv[])
1145 if (argc == 0 || argc > 2 ||
1146 (argc == 1 && !another(&argc, &argv, "remote-directory"))) {
1147 UPRINTF("usage: %s remote-directory\n", argv[0]);
1151 r = command("CWD %s", argv[1]);
1152 if (r == ERROR && code == 500) {
1154 fputs("CWD command not recognized, trying XCWD.\n",
1156 r = command("XCWD %s", argv[1]);
1158 if (r == COMPLETE) {
1165 * Set current working directory on local machine.
1168 lcd(int argc, char *argv[])
1175 argv[1] = localhome;
1178 UPRINTF("usage: %s [local-directory]\n", argv[0]);
1181 if ((locdir = globulize(argv[1])) == NULL)
1183 if (chdir(locdir) == -1)
1184 warn("Can't chdir `%s'", locdir);
1188 fprintf(ttyout, "Local directory now: %s\n", localcwd);
1191 fprintf(ttyout, "Unable to determine local directory\n");
1198 * Delete a single file.
1201 delete(int argc, char *argv[])
1204 if (argc == 0 || argc > 2 ||
1205 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
1206 UPRINTF("usage: %s remote-file\n", argv[0]);
1210 if (command("DELE %s", argv[1]) == COMPLETE)
1215 * Delete multiple files.
1218 mdelete(int argc, char *argv[])
1225 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
1226 UPRINTF("usage: %s [remote-files]\n", argv[0]);
1231 oldintr = xsignal(SIGINT, mintr);
1232 if (sigsetjmp(jabort, 1))
1234 while ((cp = remglob(argv, 0, NULL)) != NULL) {
1239 if (mflag && confirm(argv[0], cp)) {
1240 if (command("DELE %s", cp) == COMPLETE)
1242 if (!mflag && fromatty) {
1243 ointer = interactive;
1245 if (confirm(argv[0], NULL)) {
1248 interactive = ointer;
1252 (void)xsignal(SIGINT, oldintr);
1257 * Rename a remote file.
1260 renamefile(int argc, char *argv[])
1263 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name")))
1265 if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
1267 UPRINTF("usage: %s from-name to-name\n", argv[0]);
1271 if (command("RNFR %s", argv[1]) == CONTINUE &&
1272 command("RNTO %s", argv[2]) == COMPLETE)
1277 * Get a directory listing of remote files.
1278 * Supports being invoked as:
1284 * pdir, pls LIST |$PAGER
1285 * mmlsd MLSD |$PAGER
1288 ls(int argc, char *argv[])
1291 char *remdir, *locfile;
1292 int freelocfile, pagecmd, mlsdcmd;
1296 freelocfile = pagecmd = mlsdcmd = 0;
1298 * the only commands that start with `p' are
1299 * the `pager' versions.
1301 if (argv[0][0] == 'p')
1303 if (strcmp(argv[0] + pagecmd , "mlsd") == 0) {
1304 if (! features[FEAT_MLST]) {
1306 "MLSD is not supported by the remote server.\n");
1316 else if (strcmp(argv[0] + pagecmd, "nlist") == 0)
1325 if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
1327 if (pagecmd || mlsdcmd)
1328 UPRINTF("usage: %s [remote-path]\n", argv[0]);
1330 UPRINTF("usage: %s [remote-path [local-file]]\n",
1340 p = getoptionvalue("pager");
1343 len = strlen(p) + 2;
1344 locfile = ftp_malloc(len);
1346 (void)strlcpy(locfile + 1, p, len - 1);
1348 } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
1349 if ((locfile = globulize(locfile)) == NULL ||
1350 !confirm("output to local-file:", locfile)) {
1356 recvrequest(cmd, locfile, remdir, "w", 0, 0);
1358 if (freelocfile && locfile)
1359 (void)free(locfile);
1363 * Get a directory listing of multiple remote files.
1366 mls(int argc, char *argv[])
1371 char *mode, *dest, *odest;
1375 if (argc < 2 && !another(&argc, &argv, "remote-files"))
1377 if (argc < 3 && !another(&argc, &argv, "local-file")) {
1379 UPRINTF("usage: %s remote-files local-file\n", argv[0]);
1383 odest = dest = argv[argc - 1];
1384 argv[argc - 1] = NULL;
1385 if (strcmp(dest, "-") && *dest != '|')
1386 if (((dest = globulize(dest)) == NULL) ||
1387 !confirm("output to local-file:", dest)) {
1391 dolist = strcmp(argv[0], "mls");
1393 oldintr = xsignal(SIGINT, mintr);
1394 if (sigsetjmp(jabort, 1))
1396 for (i = 1; mflag && i < argc-1 && connected; i++) {
1397 mode = (i == 1) ? "w" : "a";
1398 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
1400 if (!mflag && fromatty) {
1401 ointer = interactive;
1403 if (confirm(argv[0], NULL)) {
1406 interactive = ointer;
1409 (void)xsignal(SIGINT, oldintr);
1411 if (dest != odest) /* free up after globulize() */
1420 shell(int argc, char *argv[])
1424 char shellnam[MAXPATHLEN], *shell, *namep;
1428 UPRINTF("usage: %s [command [args]]\n", argv[0]);
1432 oldintr = xsignal(SIGINT, SIG_IGN);
1433 if ((pid = fork()) == 0) {
1434 for (pid = 3; pid < 20; pid++)
1436 (void)xsignal(SIGINT, SIG_DFL);
1437 shell = getenv("SHELL");
1439 shell = _PATH_BSHELL;
1440 namep = strrchr(shell, '/');
1445 (void)strlcpy(shellnam, namep, sizeof(shellnam));
1447 fputs(shell, ttyout);
1451 execl(shell, shellnam, "-c", altarg, (char *)0);
1454 execl(shell, shellnam, (char *)0);
1456 warn("Can't execute `%s'", shell);
1461 while (wait(&wait_status) != pid)
1463 (void)xsignal(SIGINT, oldintr);
1465 warn("Can't fork a subshell; try again later");
1472 * Send new user information (re-login)
1475 user(int argc, char *argv[])
1478 char emptypass[] = "";
1484 (void)another(&argc, &argv, "username");
1485 if (argc < 2 || argc > 4) {
1487 UPRINTF("usage: %s username [password [account]]\n",
1492 n = command("USER %s", argv[1]);
1493 if (n == CONTINUE) {
1495 password = getpass("Password: ");
1496 if (password == NULL)
1497 password = emptypass;
1501 n = command("PASS %s", password);
1502 memset(password, 0, strlen(password));
1504 if (n == CONTINUE) {
1507 password = getpass("Account: ");
1508 if (password == NULL)
1509 password = emptypass;
1513 n = command("ACCT %s", password);
1514 memset(password, 0, strlen(password));
1516 if (n != COMPLETE) {
1517 fputs("Login failed.\n", ttyout);
1520 if (!aflag && argc == 4) {
1522 (void)command("ACCT %s", password);
1523 memset(password, 0, strlen(password));
1530 * Print working directory on remote machine.
1534 pwd(int argc, char *argv[])
1539 UPRINTF("usage: %s\n", argv[0]);
1545 fprintf(ttyout, "Unable to determine remote directory\n");
1547 fprintf(ttyout, "Remote directory: %s\n", remotecwd);
1553 * Print working directory on local machine.
1556 lpwd(int argc, char *argv[])
1561 UPRINTF("usage: %s\n", argv[0]);
1567 fprintf(ttyout, "Unable to determine local directory\n");
1569 fprintf(ttyout, "Local directory: %s\n", localcwd);
1578 makedir(int argc, char *argv[])
1582 if (argc == 0 || argc > 2 ||
1583 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1584 UPRINTF("usage: %s directory-name\n", argv[0]);
1588 r = command("MKD %s", argv[1]);
1589 if (r == ERROR && code == 500) {
1591 fputs("MKD command not recognized, trying XMKD.\n",
1593 r = command("XMKD %s", argv[1]);
1600 * Remove a directory.
1603 removedir(int argc, char *argv[])
1607 if (argc == 0 || argc > 2 ||
1608 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1609 UPRINTF("usage: %s directory-name\n", argv[0]);
1613 r = command("RMD %s", argv[1]);
1614 if (r == ERROR && code == 500) {
1616 fputs("RMD command not recognized, trying XRMD.\n",
1618 r = command("XRMD %s", argv[1]);
1625 * Send a line, verbatim, to the remote machine.
1628 quote(int argc, char *argv[])
1632 (argc == 1 && !another(&argc, &argv, "command line to send"))) {
1633 UPRINTF("usage: %s line-to-send\n", argv[0]);
1637 quote1("", argc, argv);
1641 * Send a SITE command to the remote machine. The line
1642 * is sent verbatim to the remote machine, except that the
1643 * word "SITE" is added at the front.
1646 site(int argc, char *argv[])
1650 (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
1651 UPRINTF("usage: %s line-to-send\n", argv[0]);
1655 quote1("SITE ", argc, argv);
1659 * Turn argv[1..argc) into a space-separated string, then prepend initial text.
1660 * Send the result as a one-line command and get response.
1663 quote1(const char *initial, int argc, char *argv[])
1666 char buf[BUFSIZ]; /* must be >= sizeof(line) */
1668 (void)strlcpy(buf, initial, sizeof(buf));
1669 for (i = 1; i < argc; i++) {
1670 (void)strlcat(buf, argv[i], sizeof(buf));
1672 (void)strlcat(buf, " ", sizeof(buf));
1674 if (command("%s", buf) == PRELIM) {
1675 while (getreply(0) == PRELIM)
1682 do_chmod(int argc, char *argv[])
1685 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode")))
1687 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
1689 UPRINTF("usage: %s mode remote-file\n", argv[0]);
1693 (void)command("SITE CHMOD %s %s", argv[1], argv[2]);
1696 #define COMMAND_1ARG(argc, argv, cmd) \
1700 command(cmd " %s", argv[1])
1703 do_umask(int argc, char *argv[])
1705 int oldverbose = verbose;
1708 UPRINTF("usage: %s [umask]\n", argv[0]);
1713 COMMAND_1ARG(argc, argv, "SITE UMASK");
1714 verbose = oldverbose;
1718 idlecmd(int argc, char *argv[])
1720 int oldverbose = verbose;
1722 if (argc < 1 || argc > 2) {
1723 UPRINTF("usage: %s [seconds]\n", argv[0]);
1728 COMMAND_1ARG(argc, argv, "SITE IDLE");
1729 verbose = oldverbose;
1733 * Ask the other side for help.
1736 rmthelp(int argc, char *argv[])
1738 int oldverbose = verbose;
1741 UPRINTF("usage: %s\n", argv[0]);
1746 COMMAND_1ARG(argc, argv, "HELP");
1747 verbose = oldverbose;
1751 * Terminate session and exit.
1752 * May be called with 0, NULL.
1756 quit(int argc, char *argv[])
1759 /* this may be called with argc == 0, argv == NULL */
1760 if (argc == 0 && argv != NULL) {
1761 UPRINTF("usage: %s\n", argv[0]);
1766 disconnect(0, NULL);
1769 disconnect(0, NULL);
1774 * Terminate session, but don't exit.
1775 * May be called with 0, NULL.
1778 disconnect(int argc, char *argv[])
1781 /* this may be called with argc == 0, argv == NULL */
1782 if (argc == 0 && argv != NULL) {
1783 UPRINTF("usage: %s\n", argv[0]);
1789 (void)command("QUIT");
1794 account(int argc, char *argv[])
1797 char emptypass[] = "";
1799 if (argc == 0 || argc > 2) {
1800 UPRINTF("usage: %s [password]\n", argv[0]);
1807 ap = getpass("Account:");
1811 (void)command("ACCT %s", ap);
1812 memset(ap, 0, strlen(ap));
1815 sigjmp_buf abortprox;
1818 proxabort(int notused)
1833 siglongjmp(abortprox, 1);
1837 doproxy(int argc, char *argv[])
1843 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
1844 UPRINTF("usage: %s command\n", argv[0]);
1848 c = getcmd(argv[1]);
1849 if (c == (struct cmd *) -1) {
1850 fputs("?Ambiguous command.\n", ttyout);
1855 fputs("?Invalid command.\n", ttyout);
1860 fputs("?Invalid proxy command.\n", ttyout);
1864 if (sigsetjmp(abortprox, 1)) {
1868 oldintr = xsignal(SIGINT, proxabort);
1870 if (c->c_conn && !connected) {
1871 fputs("Not connected.\n", ttyout);
1873 (void)xsignal(SIGINT, oldintr);
1877 cmdpos = strcspn(line, " \t");
1878 if (cmdpos > 0) /* remove leading "proxy " from input buffer */
1879 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
1880 argv[1] = c->c_name;
1881 (*c->c_handler)(argc-1, argv+1);
1889 (void)xsignal(SIGINT, oldintr);
1893 setcase(int argc, char *argv[])
1896 code = togglevar(argc, argv, &mcase, "Case mapping");
1900 * convert the given name to lower case if it's all upper case, into
1901 * a static buffer which is returned to the caller
1904 docase(char *dst, size_t dlen, const char *src)
1909 for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
1911 if (islower((unsigned char)dst[i]))
1917 for (i = 0; dst[i] != '\0'; i++)
1918 if (isupper((unsigned char)dst[i]))
1919 dst[i] = tolower((unsigned char)dst[i]);
1925 setcr(int argc, char *argv[])
1928 code = togglevar(argc, argv, &crflag, "Carriage Return stripping");
1932 setntrans(int argc, char *argv[])
1935 if (argc == 0 || argc > 3) {
1936 UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
1942 fputs("Ntrans off.\n", ttyout);
1948 (void)strlcpy(ntin, argv[1], sizeof(ntin));
1953 (void)strlcpy(ntout, argv[2], sizeof(ntout));
1957 dotrans(char *dst, size_t dlen, const char *src)
1963 for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
1965 for (cp1 = src; *cp1; cp1++) {
1967 for (i = 0; *(ntin + i) && i < 16; i++) {
1968 if (*cp1 == *(ntin + i)) {
1971 *cp2++ = *(ntout + i);
1972 if (cp2 - dst >= dlen - 1)
1988 setnmap(int argc, char *argv[])
1994 fputs("Nmap off.\n", ttyout);
1999 (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
2000 UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
2006 cp = strchr(altarg, ' ');
2011 cp = strchr(altarg, ' ');
2014 (void)strlcpy(mapin, altarg, MAXPATHLEN);
2015 while (*++cp == ' ')
2017 (void)strlcpy(mapout, cp, MAXPATHLEN);
2021 domap(char *dst, size_t dlen, const char *src)
2023 const char *cp1 = src;
2025 const char *tp[9], *te[9];
2026 int i, toks[9], toknum = 0, match = 1;
2028 for (i=0; i < 9; ++i) {
2031 while (match && *cp1 && *cp2) {
2034 if (*++cp2 != *cp1) {
2039 if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
2040 if (*cp1 != *(++cp2+1)) {
2041 toks[toknum = *cp2 - '1']++;
2043 while (*++cp1 && *(cp2+1)
2057 if (match && *cp1) {
2060 if (match && *cp2) {
2064 if (!match && *cp1) /* last token mismatch */
2081 if (*++cp1 == '$' &&
2082 isdigit((unsigned char)*(cp1+1))) {
2083 if (*++cp1 == '0') {
2084 const char *cp3 = src;
2091 else if (toks[toknum = *cp1 - '1']) {
2092 const char *cp3 = tp[toknum];
2094 while (cp3 != te[toknum]) {
2101 while (*cp1 && *cp1 != ',' &&
2106 else if (*cp1 == '$' &&
2107 isdigit((unsigned char)*(cp1+1))) {
2108 if (*++cp1 == '0') {
2109 const char *cp3 = src;
2115 else if (toks[toknum =
2117 const char *cp3=tp[toknum];
2131 "nmap: unbalanced brackets.\n",
2139 while (*++cp1 && *cp1 != ']') {
2140 if (*cp1 == '\\' && *(cp1 + 1)) {
2146 "nmap: unbalanced brackets.\n",
2163 if (isdigit((unsigned char)*(cp1 + 1))) {
2164 if (*++cp1 == '0') {
2165 const char *cp3 = src;
2171 else if (toks[toknum = *cp1 - '1']) {
2172 const char *cp3 = tp[toknum];
2174 while (cp3 != te[toknum]) {
2180 /* intentional drop through */
2188 return *dst ? dst : src;
2192 setpassive(int argc, char *argv[])
2196 passivemode = !passivemode;
2197 activefallback = passivemode;
2198 } else if (argc != 2) {
2200 UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
2203 } else if (strcasecmp(argv[1], "on") == 0) {
2206 } else if (strcasecmp(argv[1], "off") == 0) {
2209 } else if (strcasecmp(argv[1], "auto") == 0) {
2214 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
2215 onoff(passivemode), onoff(activefallback));
2220 setepsv4(int argc, char *argv[])
2223 code = togglevar(argc, argv, &epsv4,
2224 verbose ? "EPSV/EPRT on IPv4" : NULL);
2229 setsunique(int argc, char *argv[])
2232 code = togglevar(argc, argv, &sunique, "Store unique");
2236 setrunique(int argc, char *argv[])
2239 code = togglevar(argc, argv, &runique, "Receive unique");
2243 parserate(int argc, char *argv[], int cmdlineopt)
2245 int dir, max, incr, showonly;
2246 sigfunc oldusr1, oldusr2;
2248 if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
2252 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
2256 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
2260 dir = max = incr = showonly = 0;
2263 #define RATE_ALL (RATE_GET | RATE_PUT)
2265 if (strcasecmp(argv[1], "all") == 0)
2267 else if (strcasecmp(argv[1], "get") == 0)
2269 else if (strcasecmp(argv[1], "put") == 0)
2275 if ((max = strsuftoi(argv[2])) < 0)
2281 if ((incr = strsuftoi(argv[3])) <= 0)
2286 oldusr1 = xsignal(SIGUSR1, SIG_IGN);
2287 oldusr2 = xsignal(SIGUSR2, SIG_IGN);
2288 if (dir & RATE_GET) {
2291 rate_get_incr = incr;
2293 if (!cmdlineopt || verbose)
2295 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
2296 onoff(rate_get), rate_get, rate_get_incr);
2298 if (dir & RATE_PUT) {
2301 rate_put_incr = incr;
2303 if (!cmdlineopt || verbose)
2305 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
2306 onoff(rate_put), rate_put, rate_put_incr);
2308 (void)xsignal(SIGUSR1, oldusr1);
2309 (void)xsignal(SIGUSR2, oldusr2);
2314 setrate(int argc, char *argv[])
2317 code = parserate(argc, argv, 0);
2320 /* change directory to parent directory */
2322 cdup(int argc, char *argv[])
2327 UPRINTF("usage: %s\n", argv[0]);
2331 r = command("CDUP");
2332 if (r == ERROR && code == 500) {
2334 fputs("CDUP command not recognized, trying XCUP.\n",
2336 r = command("XCUP");
2338 if (r == COMPLETE) {
2345 * Restart transfer at specific point
2348 restart(int argc, char *argv[])
2351 if (argc == 0 || argc > 2) {
2352 UPRINTF("usage: %s [restart-point]\n", argv[0]);
2356 if (! features[FEAT_REST_STREAM]) {
2358 "Restart is not supported by the remote server.\n");
2365 rp = STRTOLL(argv[1], &ep, 10);
2366 if (rp < 0 || *ep != '\0')
2367 fprintf(ttyout, "restart: Invalid offset `%s'\n",
2372 if (restart_point == 0)
2373 fputs("No restart point defined.\n", ttyout);
2376 "Restarting at " LLF " for next get, put or append\n",
2377 (LLT)restart_point);
2381 * Show remote system type
2384 syst(int argc, char *argv[])
2386 int oldverbose = verbose;
2389 UPRINTF("usage: %s\n", argv[0]);
2393 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2394 (void)command("SYST");
2395 verbose = oldverbose;
2399 macdef(int argc, char *argv[])
2407 fputs("Limit of 16 macros have already been defined.\n",
2412 if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
2414 UPRINTF("usage: %s macro_name\n", argv[0]);
2420 "Enter macro line by line, terminating it with a null line.\n",
2422 (void)strlcpy(macros[macnum].mac_name, argv[1],
2423 sizeof(macros[macnum].mac_name));
2425 macros[macnum].mac_start = macbuf;
2427 macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
2428 tmp = macros[macnum].mac_start;
2429 while (tmp != macbuf+4096) {
2430 if ((c = getchar()) == EOF) {
2431 fputs("macdef: end of file encountered.\n", ttyout);
2435 if ((*tmp = c) == '\n') {
2436 if (tmp == macros[macnum].mac_start) {
2437 macros[macnum++].mac_end = tmp;
2441 if (*(tmp-1) == '\0') {
2442 macros[macnum++].mac_end = tmp - 1;
2451 while ((c = getchar()) != '\n' && c != EOF)
2453 if (c == EOF || getchar() == '\n') {
2454 fputs("Macro not defined - 4K buffer exceeded.\n",
2463 * Get size of file on remote machine
2466 sizecmd(int argc, char *argv[])
2470 if (argc == 0 || argc > 2 ||
2471 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2472 UPRINTF("usage: %s remote-file\n", argv[0]);
2476 size = remotesize(argv[1], 1);
2479 "%s\t" LLF "\n", argv[1], (LLT)size);
2484 * Get last modification time of file on remote machine
2487 modtime(int argc, char *argv[])
2491 if (argc == 0 || argc > 2 ||
2492 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2493 UPRINTF("usage: %s remote-file\n", argv[0]);
2497 mtime = remotemodtime(argv[1], 1);
2499 fprintf(ttyout, "%s\t%s", argv[1], asctime(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;