1 /* $NetBSD: cmds.c,v 1.125 2008/05/10 00:05:31 skd 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.
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
37 * Copyright (c) 1985, 1989, 1993, 1994
38 * The Regents of the University of California. All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * Copyright (C) 1997 and 1998 WIDE Project.
67 * All rights reserved.
69 * Redistribution and use in source and binary forms, with or without
70 * modification, are permitted provided that the following conditions
72 * 1. Redistributions of source code must retain the above copyright
73 * notice, this list of conditions and the following disclaimer.
74 * 2. Redistributions in binary form must reproduce the above copyright
75 * notice, this list of conditions and the following disclaimer in the
76 * documentation and/or other materials provided with the distribution.
77 * 3. Neither the name of the project nor the names of its contributors
78 * may be used to endorse or promote products derived from this software
79 * without specific prior written permission.
81 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
82 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
83 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 #include <sys/cdefs.h>
97 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
99 __RCSID("$NetBSD: cmds.c,v 1.125 2008/05/10 00:05:31 skd Exp $");
101 #endif /* not lint */
104 * FTP User Program -- Command Routines.
106 #include <sys/types.h>
107 #include <sys/socket.h>
108 #include <sys/stat.h>
109 #include <sys/wait.h>
110 #include <arpa/ftp.h>
128 static struct types {
134 { "ascii", "A", TYPE_A, 0 },
135 { "binary", "I", TYPE_I, 0 },
136 { "image", "I", TYPE_I, 0 },
137 { "ebcdic", "E", TYPE_E, 0 },
138 { "tenex", "L", TYPE_L, bytename },
142 static sigjmp_buf jabort;
144 static int confirm(const char *, const char *);
145 static void mintr(int);
146 static void mabort(const char *);
148 static const char *doprocess(char *, size_t, const char *, int, int, int);
149 static const char *domap(char *, size_t, const char *);
150 static const char *docase(char *, size_t, const char *);
151 static const char *dotrans(char *, size_t, const char *);
154 * Confirm if "cmd" is to be performed upon "file".
155 * If "file" is NULL, generate a "Continue with" prompt instead.
158 confirm(const char *cmd, const char *file)
160 const char *errormsg;
162 const char *promptleft, *promptright;
164 if (!interactive || confirmrest)
167 promptleft = "Continue with";
174 fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright);
175 (void)fflush(ttyout);
176 if (getline(stdin, line, sizeof(line), &errormsg) < 0) {
178 fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd);
181 switch (tolower((unsigned char)*line)) {
185 "Prompting off for duration of %s.\n", cmd);
189 fputs("Interactive mode: off.\n", ttyout);
193 fprintf(ttyout, "%s aborted.\n", cmd);
199 " confirmation options:\n"
200 "\ta answer `yes' for the duration of %s\n"
201 "\tn answer `no' for this file\n"
202 "\tp turn off `prompt' mode\n"
203 "\tq stop the current %s\n"
204 "\ty answer `yes' for this file\n"
205 "\t? this help list\n",
207 continue; /* back to while(1) */
218 settype(int argc, char *argv[])
223 if (argc == 0 || argc > 2) {
226 UPRINTF("usage: %s [", argv[0]);
228 for (p = types; p->t_name; p++) {
229 fprintf(ttyout, "%s%s", sep, p->t_name);
232 fputs(" ]\n", ttyout);
237 fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
241 for (p = types; p->t_name; p++)
242 if (strcmp(argv[1], p->t_name) == 0)
244 if (p->t_name == 0) {
245 fprintf(ttyout, "%s: unknown mode.\n", argv[1]);
249 if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
250 comret = command("TYPE %s %s", p->t_mode, p->t_arg);
252 comret = command("TYPE %s", p->t_mode);
253 if (comret == COMPLETE) {
254 (void)strlcpy(typename, p->t_name, sizeof(typename));
255 curtype = type = p->t_type;
260 * Internal form of settype; changes current type in use with server
261 * without changing our notion of the type for data transfers.
262 * Used to change to and from ascii for listings.
265 changetype(int newtype, int show)
268 int comret, oldverbose = verbose;
272 if (newtype == curtype)
274 if (ftp_debug == 0 && show == 0)
276 for (p = types; p->t_name; p++)
277 if (newtype == p->t_type)
279 if (p->t_name == 0) {
280 errx(1, "changetype: unknown type %d", newtype);
282 if (newtype == TYPE_L && bytename[0] != '\0')
283 comret = command("TYPE %s %s", p->t_mode, bytename);
285 comret = command("TYPE %s", p->t_mode);
286 if (comret == COMPLETE)
288 verbose = oldverbose;
298 * Set binary transfer type.
302 setbinary(int argc, char *argv[])
306 UPRINTF("usage: %s\n", argv[0]);
315 * Set ascii transfer type.
319 setascii(int argc, char *argv[])
323 UPRINTF("usage: %s\n", argv[0]);
332 * Set tenex transfer type.
336 settenex(int argc, char *argv[])
340 UPRINTF("usage: %s\n", argv[0]);
349 * Set file transfer mode.
353 setftmode(int argc, char *argv[])
357 UPRINTF("usage: %s mode-name\n", argv[0]);
361 fprintf(ttyout, "We only support %s mode, sorry.\n", modename);
366 * Set file transfer format.
370 setform(int argc, char *argv[])
374 UPRINTF("usage: %s format\n", argv[0]);
378 fprintf(ttyout, "We only support %s format, sorry.\n", formname);
383 * Set file transfer structure.
387 setstruct(int argc, char *argv[])
391 UPRINTF("usage: %s struct-mode\n", argv[0]);
395 fprintf(ttyout, "We only support %s structure, sorry.\n", structname);
400 * Send a single file.
403 put(int argc, char *argv[])
405 char buf[MAXPATHLEN];
416 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file")))
418 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
420 UPRINTF("usage: %s local-file [remote-file]\n", argv[0]);
424 if ((locfile = globulize(argv[1])) == NULL) {
429 if (loc) /* If argv[2] is a copy of the old argv[1], update it */
431 cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
432 remfile = doprocess(buf, sizeof(buf), remfile,
433 0, loc && ntflag, loc && mapflag);
434 sendrequest(cmd, locfile, remfile,
435 locfile != argv[1] || remfile != argv[2]);
440 doprocess(char *dst, size_t dlen, const char *src,
441 int casef, int transf, int mapf)
444 src = docase(dst, dlen, src);
446 src = dotrans(dst, dlen, src);
448 src = domap(dst, dlen, src);
453 * Send multiple files.
456 mput(int argc, char *argv[])
463 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
464 UPRINTF("usage: %s local-files\n", argv[0]);
469 oldintr = xsignal(SIGINT, mintr);
470 if (sigsetjmp(jabort, 1))
475 while ((cp = remglob(argv, 0, NULL)) != NULL) {
476 if (*cp == '\0' || !connected) {
480 if (mflag && confirm(argv[0], cp)) {
481 char buf[MAXPATHLEN];
482 tp = doprocess(buf, sizeof(buf), cp,
483 mcase, ntflag, mapflag);
484 sendrequest((sunique) ? "STOU" : "STOR",
485 cp, tp, cp != tp || !interactive);
486 if (!mflag && fromatty) {
487 ointer = interactive;
489 if (confirm(argv[0], NULL)) {
492 interactive = ointer;
498 for (i = 1; i < argc && connected; i++) {
504 if (mflag && confirm(argv[0], argv[i])) {
505 char buf[MAXPATHLEN];
506 tp = doprocess(buf, sizeof(buf), argv[i],
508 sendrequest((sunique) ? "STOU" : "STOR",
509 argv[i], tp, tp != argv[i] || !interactive);
510 if (!mflag && fromatty) {
511 ointer = interactive;
513 if (confirm(argv[0], NULL)) {
516 interactive = ointer;
522 memset(&gl, 0, sizeof(gl));
523 flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
524 if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
525 warnx("Glob pattern `%s' not found", argv[i]);
529 for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
531 if (mflag && confirm(argv[0], *cpp)) {
532 char buf[MAXPATHLEN];
534 tp = doprocess(buf, sizeof(buf), *cpp,
536 sendrequest((sunique) ? "STOU" : "STOR",
537 *cpp, tp, *cpp != tp || !interactive);
538 if (!mflag && fromatty) {
539 ointer = interactive;
541 if (confirm(argv[0], NULL)) {
544 interactive = ointer;
551 (void)xsignal(SIGINT, oldintr);
556 reget(int argc, char *argv[])
559 (void)getit(argc, argv, 1, "r+");
563 get(int argc, char *argv[])
566 (void)getit(argc, argv, 0, restart_point ? "r+" : "w" );
571 * If restartit is 1, restart the xfer always.
572 * If restartit is -1, restart the xfer only if the remote file is newer.
575 getit(int argc, char *argv[], int restartit, const char *mode)
578 char *remfile, *olocfile;
580 char buf[MAXPATHLEN];
588 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file")))
590 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
592 UPRINTF("usage: %s remote-file [local-file]\n", argv[0]);
597 if ((olocfile = globulize(argv[2])) == NULL) {
601 locfile = doprocess(buf, sizeof(buf), olocfile,
602 loc && mcase, loc && ntflag, loc && mapflag);
607 if (! features[FEAT_REST_STREAM]) {
609 "Restart is not supported by the remote server.\n");
612 ret = stat(locfile, &stbuf);
613 if (restartit == 1) {
615 warn("Can't stat `%s'", locfile);
618 restart_point = stbuf.st_size;
623 mtime = remotemodtime(argv[1], 0);
626 if (stbuf.st_mtime >= mtime) {
634 recvrequest("RETR", locfile, remfile, mode,
635 remfile != argv[1] || locfile != argv[2], loc);
638 (void)free(olocfile);
649 write(fileno(ttyout), "\n", 1);
650 siglongjmp(jabort, 1);
654 mabort(const char *cmd)
658 if (mflag && fromatty) {
659 ointer = interactive;
663 if (confirm(cmd, NULL)) {
664 interactive = ointer;
668 interactive = ointer;
675 * Get multiple files.
678 mget(int argc, char *argv[])
687 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
688 UPRINTF("usage: %s remote-files\n", argv[0]);
695 if (strcmp(argv[0], "mreget") == 0) {
696 if (! features[FEAT_REST_STREAM]) {
698 "Restart is not supported by the remote server.\n");
703 oldintr = xsignal(SIGINT, mintr);
704 if (sigsetjmp(jabort, 1))
706 while ((cp = remglob(argv, proxy, NULL)) != NULL) {
707 char buf[MAXPATHLEN];
708 if (*cp == '\0' || !connected) {
714 if (! fileindir(cp, localcwd)) {
715 fprintf(ttyout, "Skipping non-relative filename `%s'\n",
719 if (!confirm(argv[0], cp))
721 tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag);
725 if (stat(tp, &stbuf) == 0)
726 restart_point = stbuf.st_size;
728 warn("Can't stat `%s'", tp);
730 recvrequest("RETR", tp, cp, restart_point ? "r+" : "w",
731 tp != cp || !interactive, 1);
733 if (!mflag && fromatty) {
734 ointer = interactive;
736 if (confirm(argv[0], NULL))
738 interactive = ointer;
741 (void)xsignal(SIGINT, oldintr);
746 * Read list of filenames from a local file and get those
749 fget(int argc, char *argv[])
753 char buf[MAXPATHLEN];
756 UPRINTF("usage: %s localfile\n", argv[0]);
761 fp = fopen(argv[1], "r");
763 fprintf(ttyout, "Can't open source file %s\n", argv[1]);
769 mode = restart_point ? "r+" : "w";
771 while (getline(fp, buf, sizeof(buf), NULL) >= 0) {
775 (void)getit(argc, argv, 0, mode);
784 return (bool ? "on" : "off");
792 status(int argc, char *argv[])
796 UPRINTF("usage: %s\n", argv[0]);
802 fprintf(ttyout, "Connected %sto %s.\n",
803 connected == -1 ? "and logged in" : "", hostname);
805 fputs("Not connected.\n", ttyout);
809 fprintf(ttyout, "Connected for proxy commands to %s.\n",
813 fputs("No proxy connection.\n", ttyout);
817 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
818 *gateserver ? gateserver : "(none)", gateport);
819 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
820 onoff(passivemode), onoff(activefallback));
821 fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
822 modename, typename, formname, structname);
823 fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
824 onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob));
825 fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n",
826 onoff(sunique), onoff(runique));
827 fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve));
828 fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase),
831 fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout);
834 fputs("Ntrans: off.\n", ttyout);
837 fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout);
840 fputs("Nmap: off.\n", ttyout);
843 "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
844 onoff(hash), mark, onoff(progress));
846 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
847 onoff(rate_get), rate_get, rate_get_incr);
849 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
850 onoff(rate_put), rate_put, rate_put_incr);
852 "Socket buffer sizes: send %d, receive %d.\n",
853 sndbuf_size, rcvbuf_size);
854 fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
855 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
856 epsv4bad ? " (disabled for this connection)" : "");
857 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv6: %s%s.\n", onoff(epsv6),
858 epsv6bad ? " (disabled for this connection)" : "");
859 fprintf(ttyout, "Command line editing: %s.\n",
860 #ifdef NO_EDITCOMPLETE
861 "support not compiled in"
862 #else /* !def NO_EDITCOMPLETE */
864 #endif /* !def NO_EDITCOMPLETE */
869 fputs("Macros:\n", ttyout);
870 for (i=0; i<macnum; i++) {
871 fprintf(ttyout, "\t%s\n", macros[i].mac_name);
874 #endif /* !def NO_STATUS */
875 fprintf(ttyout, "Version: %s %s\n", FTP_PRODUCT, FTP_VERSION);
883 togglevar(int argc, char *argv[], int *var, const char *mesg)
887 } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
889 } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
892 UPRINTF("usage: %s [ on | off ]\n", argv[0]);
896 fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
901 * Set beep on cmd completed mode.
905 setbell(int argc, char *argv[])
908 code = togglevar(argc, argv, &bell, "Bell mode");
912 * Set command line editing
916 setedit(int argc, char *argv[])
919 #ifdef NO_EDITCOMPLETE
921 UPRINTF("usage: %s\n", argv[0]);
926 fputs("Editing support not compiled in; ignoring command.\n",
928 #else /* !def NO_EDITCOMPLETE */
929 code = togglevar(argc, argv, &editing, "Editing mode");
931 #endif /* !def NO_EDITCOMPLETE */
935 * Turn on packet tracing.
939 settrace(int argc, char *argv[])
942 code = togglevar(argc, argv, &trace, "Packet tracing");
946 * Toggle hash mark printing during transfers, or set hash mark bytecount.
950 sethash(int argc, char *argv[])
954 else if (argc != 2) {
955 UPRINTF("usage: %s [ on | off | bytecount ]\n",
959 } else if (strcasecmp(argv[1], "on") == 0)
961 else if (strcasecmp(argv[1], "off") == 0)
966 nmark = strsuftoi(argv[1]);
968 fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
976 fprintf(ttyout, "Hash mark printing %s", onoff(hash));
978 fprintf(ttyout, " (%d bytes/hash mark)", mark);
979 fputs(".\n", ttyout);
986 * Turn on printing of server echo's.
990 setverbose(int argc, char *argv[])
993 code = togglevar(argc, argv, &verbose, "Verbose mode");
997 * Toggle PORT/LPRT cmd use before each data connection.
1001 setport(int argc, char *argv[])
1004 code = togglevar(argc, argv, &sendport, "Use of PORT/LPRT cmds");
1008 * Toggle transfer progress bar.
1012 setprogress(int argc, char *argv[])
1015 code = togglevar(argc, argv, &progress, "Progress bar");
1021 * Turn on interactive prompting during mget, mput, and mdelete.
1025 setprompt(int argc, char *argv[])
1028 code = togglevar(argc, argv, &interactive, "Interactive mode");
1032 * Toggle gate-ftp mode, or set gate-ftp server
1036 setgate(int argc, char *argv[])
1038 static char gsbuf[MAXHOSTNAMELEN];
1040 if (argc == 0 || argc > 3) {
1042 "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
1045 } else if (argc < 2) {
1046 gatemode = !gatemode;
1048 if (argc == 2 && strcasecmp(argv[1], "on") == 0)
1050 else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
1054 gateport = ftp_strdup(argv[2]);
1055 (void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
1060 if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
1062 "Disabling gate-ftp mode - no gate-ftp server defined.\n");
1065 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n",
1066 onoff(gatemode), *gateserver ? gateserver : "(none)",
1073 * Toggle metacharacter interpretation on local file names.
1077 setglob(int argc, char *argv[])
1080 code = togglevar(argc, argv, &doglob, "Globbing");
1084 * Toggle preserving modification times on retrieved files.
1088 setpreserve(int argc, char *argv[])
1091 code = togglevar(argc, argv, &preserve, "Preserve modification times");
1095 * Set debugging mode on/off and/or set level of debugging.
1099 setdebug(int argc, char *argv[])
1101 if (argc == 0 || argc > 2) {
1102 UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
1105 } else if (argc == 2) {
1106 if (strcasecmp(argv[1], "on") == 0)
1108 else if (strcasecmp(argv[1], "off") == 0)
1113 val = strsuftoi(argv[1]);
1115 fprintf(ttyout, "%s: bad debugging value.\n",
1123 ftp_debug = !ftp_debug;
1125 options |= SO_DEBUG;
1127 options &= ~SO_DEBUG;
1128 fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
1129 code = ftp_debug > 0;
1133 * Set current working directory on remote machine.
1136 cd(int argc, char *argv[])
1140 if (argc == 0 || argc > 2 ||
1141 (argc == 1 && !another(&argc, &argv, "remote-directory"))) {
1142 UPRINTF("usage: %s remote-directory\n", argv[0]);
1146 r = command("CWD %s", argv[1]);
1147 if (r == ERROR && code == 500) {
1149 fputs("CWD command not recognized, trying XCWD.\n",
1151 r = command("XCWD %s", argv[1]);
1153 if (r == COMPLETE) {
1160 * Set current working directory on local machine.
1163 lcd(int argc, char *argv[])
1170 argv[1] = localhome;
1173 UPRINTF("usage: %s [local-directory]\n", argv[0]);
1176 if ((locdir = globulize(argv[1])) == NULL)
1178 if (chdir(locdir) == -1)
1179 warn("Can't chdir `%s'", locdir);
1183 fprintf(ttyout, "Local directory now: %s\n", localcwd);
1186 fprintf(ttyout, "Unable to determine local directory\n");
1193 * Delete a single file.
1196 delete(int argc, char *argv[])
1199 if (argc == 0 || argc > 2 ||
1200 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
1201 UPRINTF("usage: %s remote-file\n", argv[0]);
1205 if (command("DELE %s", argv[1]) == COMPLETE)
1210 * Delete multiple files.
1213 mdelete(int argc, char *argv[])
1220 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
1221 UPRINTF("usage: %s [remote-files]\n", argv[0]);
1226 oldintr = xsignal(SIGINT, mintr);
1227 if (sigsetjmp(jabort, 1))
1229 while ((cp = remglob(argv, 0, NULL)) != NULL) {
1234 if (mflag && confirm(argv[0], cp)) {
1235 if (command("DELE %s", cp) == COMPLETE)
1237 if (!mflag && fromatty) {
1238 ointer = interactive;
1240 if (confirm(argv[0], NULL)) {
1243 interactive = ointer;
1247 (void)xsignal(SIGINT, oldintr);
1252 * Rename a remote file.
1255 renamefile(int argc, char *argv[])
1258 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name")))
1260 if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
1262 UPRINTF("usage: %s from-name to-name\n", argv[0]);
1266 if (command("RNFR %s", argv[1]) == CONTINUE &&
1267 command("RNTO %s", argv[2]) == COMPLETE)
1272 * Get a directory listing of remote files.
1273 * Supports being invoked as:
1279 * pdir, pls LIST |$PAGER
1280 * mmlsd MLSD |$PAGER
1283 ls(int argc, char *argv[])
1286 char *remdir, *locfile;
1287 int freelocfile, pagecmd, mlsdcmd;
1291 freelocfile = pagecmd = mlsdcmd = 0;
1293 * the only commands that start with `p' are
1294 * the `pager' versions.
1296 if (argv[0][0] == 'p')
1298 if (strcmp(argv[0] + pagecmd , "mlsd") == 0) {
1299 if (! features[FEAT_MLST]) {
1301 "MLSD is not supported by the remote server.\n");
1311 else if (strcmp(argv[0] + pagecmd, "nlist") == 0)
1320 if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
1322 if (pagecmd || mlsdcmd)
1323 UPRINTF("usage: %s [remote-path]\n", argv[0]);
1325 UPRINTF("usage: %s [remote-path [local-file]]\n",
1335 p = getoptionvalue("pager");
1338 len = strlen(p) + 2;
1339 locfile = ftp_malloc(len);
1341 (void)strlcpy(locfile + 1, p, len - 1);
1343 } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
1344 if ((locfile = globulize(locfile)) == NULL ||
1345 !confirm("output to local-file:", locfile)) {
1351 recvrequest(cmd, locfile, remdir, "w", 0, 0);
1353 if (freelocfile && locfile)
1354 (void)free(locfile);
1358 * Get a directory listing of multiple remote files.
1361 mls(int argc, char *argv[])
1366 char *mode, *dest, *odest;
1370 if (argc < 2 && !another(&argc, &argv, "remote-files"))
1372 if (argc < 3 && !another(&argc, &argv, "local-file")) {
1374 UPRINTF("usage: %s remote-files local-file\n", argv[0]);
1378 odest = dest = argv[argc - 1];
1379 argv[argc - 1] = NULL;
1380 if (strcmp(dest, "-") && *dest != '|')
1381 if (((dest = globulize(dest)) == NULL) ||
1382 !confirm("output to local-file:", dest)) {
1386 dolist = strcmp(argv[0], "mls");
1388 oldintr = xsignal(SIGINT, mintr);
1389 if (sigsetjmp(jabort, 1))
1391 for (i = 1; mflag && i < argc-1 && connected; i++) {
1392 mode = (i == 1) ? "w" : "a";
1393 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
1395 if (!mflag && fromatty) {
1396 ointer = interactive;
1398 if (confirm(argv[0], NULL)) {
1401 interactive = ointer;
1404 (void)xsignal(SIGINT, oldintr);
1406 if (dest != odest) /* free up after globulize() */
1415 shell(int argc, char *argv[])
1419 char shellnam[MAXPATHLEN], *shell, *namep;
1423 UPRINTF("usage: %s [command [args]]\n", argv[0]);
1427 oldintr = xsignal(SIGINT, SIG_IGN);
1428 if ((pid = fork()) == 0) {
1429 for (pid = 3; pid < 20; pid++)
1431 (void)xsignal(SIGINT, SIG_DFL);
1432 shell = getenv("SHELL");
1434 shell = _PATH_BSHELL;
1435 namep = strrchr(shell, '/');
1440 (void)strlcpy(shellnam, namep, sizeof(shellnam));
1442 fputs(shell, ttyout);
1446 execl(shell, shellnam, "-c", altarg, (char *)0);
1449 execl(shell, shellnam, (char *)0);
1451 warn("Can't execute `%s'", shell);
1456 while (wait(&wait_status) != pid)
1458 (void)xsignal(SIGINT, oldintr);
1460 warn("Can't fork a subshell; try again later");
1467 * Send new user information (re-login)
1470 user(int argc, char *argv[])
1473 char emptypass[] = "";
1479 (void)another(&argc, &argv, "username");
1480 if (argc < 2 || argc > 4) {
1482 UPRINTF("usage: %s username [password [account]]\n",
1487 n = command("USER %s", argv[1]);
1488 if (n == CONTINUE) {
1490 password = getpass("Password: ");
1491 if (password == NULL)
1492 password = emptypass;
1496 n = command("PASS %s", password);
1497 memset(password, 0, strlen(password));
1499 if (n == CONTINUE) {
1502 password = getpass("Account: ");
1503 if (password == NULL)
1504 password = emptypass;
1508 n = command("ACCT %s", password);
1509 memset(password, 0, strlen(password));
1511 if (n != COMPLETE) {
1512 fputs("Login failed.\n", ttyout);
1515 if (!aflag && argc == 4) {
1517 (void)command("ACCT %s", password);
1518 memset(password, 0, strlen(password));
1525 * Print working directory on remote machine.
1529 pwd(int argc, char *argv[])
1534 UPRINTF("usage: %s\n", argv[0]);
1540 fprintf(ttyout, "Unable to determine remote directory\n");
1542 fprintf(ttyout, "Remote directory: %s\n", remotecwd);
1548 * Print working directory on local machine.
1551 lpwd(int argc, char *argv[])
1556 UPRINTF("usage: %s\n", argv[0]);
1562 fprintf(ttyout, "Unable to determine local directory\n");
1564 fprintf(ttyout, "Local directory: %s\n", localcwd);
1573 makedir(int argc, char *argv[])
1577 if (argc == 0 || argc > 2 ||
1578 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1579 UPRINTF("usage: %s directory-name\n", argv[0]);
1583 r = command("MKD %s", argv[1]);
1584 if (r == ERROR && code == 500) {
1586 fputs("MKD command not recognized, trying XMKD.\n",
1588 r = command("XMKD %s", argv[1]);
1595 * Remove a directory.
1598 removedir(int argc, char *argv[])
1602 if (argc == 0 || argc > 2 ||
1603 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1604 UPRINTF("usage: %s directory-name\n", argv[0]);
1608 r = command("RMD %s", argv[1]);
1609 if (r == ERROR && code == 500) {
1611 fputs("RMD command not recognized, trying XRMD.\n",
1613 r = command("XRMD %s", argv[1]);
1620 * Send a line, verbatim, to the remote machine.
1623 quote(int argc, char *argv[])
1627 (argc == 1 && !another(&argc, &argv, "command line to send"))) {
1628 UPRINTF("usage: %s line-to-send\n", argv[0]);
1632 quote1("", argc, argv);
1636 * Send a SITE command to the remote machine. The line
1637 * is sent verbatim to the remote machine, except that the
1638 * word "SITE" is added at the front.
1641 site(int argc, char *argv[])
1645 (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
1646 UPRINTF("usage: %s line-to-send\n", argv[0]);
1650 quote1("SITE ", argc, argv);
1654 * Turn argv[1..argc) into a space-separated string, then prepend initial text.
1655 * Send the result as a one-line command and get response.
1658 quote1(const char *initial, int argc, char *argv[])
1661 char buf[BUFSIZ]; /* must be >= sizeof(line) */
1663 (void)strlcpy(buf, initial, sizeof(buf));
1664 for (i = 1; i < argc; i++) {
1665 (void)strlcat(buf, argv[i], sizeof(buf));
1667 (void)strlcat(buf, " ", sizeof(buf));
1669 if (command("%s", buf) == PRELIM) {
1670 while (getreply(0) == PRELIM)
1677 do_chmod(int argc, char *argv[])
1680 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode")))
1682 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
1684 UPRINTF("usage: %s mode remote-file\n", argv[0]);
1688 (void)command("SITE CHMOD %s %s", argv[1], argv[2]);
1691 #define COMMAND_1ARG(argc, argv, cmd) \
1695 command(cmd " %s", argv[1])
1698 do_umask(int argc, char *argv[])
1700 int oldverbose = verbose;
1703 UPRINTF("usage: %s [umask]\n", argv[0]);
1708 COMMAND_1ARG(argc, argv, "SITE UMASK");
1709 verbose = oldverbose;
1713 idlecmd(int argc, char *argv[])
1715 int oldverbose = verbose;
1717 if (argc < 1 || argc > 2) {
1718 UPRINTF("usage: %s [seconds]\n", argv[0]);
1723 COMMAND_1ARG(argc, argv, "SITE IDLE");
1724 verbose = oldverbose;
1728 * Ask the other side for help.
1731 rmthelp(int argc, char *argv[])
1733 int oldverbose = verbose;
1736 UPRINTF("usage: %s\n", argv[0]);
1741 COMMAND_1ARG(argc, argv, "HELP");
1742 verbose = oldverbose;
1746 * Terminate session and exit.
1747 * May be called with 0, NULL.
1751 quit(int argc, char *argv[])
1754 /* this may be called with argc == 0, argv == NULL */
1755 if (argc == 0 && argv != NULL) {
1756 UPRINTF("usage: %s\n", argv[0]);
1761 disconnect(0, NULL);
1764 disconnect(0, NULL);
1769 * Terminate session, but don't exit.
1770 * May be called with 0, NULL.
1773 disconnect(int argc, char *argv[])
1776 /* this may be called with argc == 0, argv == NULL */
1777 if (argc == 0 && argv != NULL) {
1778 UPRINTF("usage: %s\n", argv[0]);
1784 (void)command("QUIT");
1789 account(int argc, char *argv[])
1792 char emptypass[] = "";
1794 if (argc == 0 || argc > 2) {
1795 UPRINTF("usage: %s [password]\n", argv[0]);
1802 ap = getpass("Account:");
1806 (void)command("ACCT %s", ap);
1807 memset(ap, 0, strlen(ap));
1810 sigjmp_buf abortprox;
1813 proxabort(int notused)
1828 siglongjmp(abortprox, 1);
1832 doproxy(int argc, char *argv[])
1838 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
1839 UPRINTF("usage: %s command\n", argv[0]);
1843 c = getcmd(argv[1]);
1844 if (c == (struct cmd *) -1) {
1845 fputs("?Ambiguous command.\n", ttyout);
1850 fputs("?Invalid command.\n", ttyout);
1855 fputs("?Invalid proxy command.\n", ttyout);
1859 if (sigsetjmp(abortprox, 1)) {
1863 oldintr = xsignal(SIGINT, proxabort);
1865 if (c->c_conn && !connected) {
1866 fputs("Not connected.\n", ttyout);
1868 (void)xsignal(SIGINT, oldintr);
1872 cmdpos = strcspn(line, " \t");
1873 if (cmdpos > 0) /* remove leading "proxy " from input buffer */
1874 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
1875 argv[1] = c->c_name;
1876 (*c->c_handler)(argc-1, argv+1);
1884 (void)xsignal(SIGINT, oldintr);
1888 setcase(int argc, char *argv[])
1891 code = togglevar(argc, argv, &mcase, "Case mapping");
1895 * convert the given name to lower case if it's all upper case, into
1896 * a static buffer which is returned to the caller
1899 docase(char *dst, size_t dlen, const char *src)
1904 for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
1906 if (islower((unsigned char)dst[i]))
1912 for (i = 0; dst[i] != '\0'; i++)
1913 if (isupper((unsigned char)dst[i]))
1914 dst[i] = tolower((unsigned char)dst[i]);
1920 setcr(int argc, char *argv[])
1923 code = togglevar(argc, argv, &crflag, "Carriage Return stripping");
1927 setntrans(int argc, char *argv[])
1930 if (argc == 0 || argc > 3) {
1931 UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
1937 fputs("Ntrans off.\n", ttyout);
1943 (void)strlcpy(ntin, argv[1], sizeof(ntin));
1948 (void)strlcpy(ntout, argv[2], sizeof(ntout));
1952 dotrans(char *dst, size_t dlen, const char *src)
1958 for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
1960 for (cp1 = src; *cp1; cp1++) {
1962 for (i = 0; *(ntin + i) && i < 16; i++) {
1963 if (*cp1 == *(ntin + i)) {
1966 *cp2++ = *(ntout + i);
1967 if (cp2 - dst >= dlen - 1)
1983 setnmap(int argc, char *argv[])
1989 fputs("Nmap off.\n", ttyout);
1994 (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
1995 UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
2001 cp = strchr(altarg, ' ');
2006 cp = strchr(altarg, ' ');
2009 (void)strlcpy(mapin, altarg, MAXPATHLEN);
2010 while (*++cp == ' ')
2012 (void)strlcpy(mapout, cp, MAXPATHLEN);
2016 domap(char *dst, size_t dlen, const char *src)
2018 const char *cp1 = src;
2020 const char *tp[9], *te[9];
2021 int i, toks[9], toknum = 0, match = 1;
2023 for (i=0; i < 9; ++i) {
2026 while (match && *cp1 && *cp2) {
2029 if (*++cp2 != *cp1) {
2034 if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
2035 if (*cp1 != *(++cp2+1)) {
2036 toks[toknum = *cp2 - '1']++;
2038 while (*++cp1 && *(cp2+1)
2052 if (match && *cp1) {
2055 if (match && *cp2) {
2059 if (!match && *cp1) /* last token mismatch */
2076 if (*++cp1 == '$' &&
2077 isdigit((unsigned char)*(cp1+1))) {
2078 if (*++cp1 == '0') {
2079 const char *cp3 = src;
2086 else if (toks[toknum = *cp1 - '1']) {
2087 const char *cp3 = tp[toknum];
2089 while (cp3 != te[toknum]) {
2096 while (*cp1 && *cp1 != ',' &&
2101 else if (*cp1 == '$' &&
2102 isdigit((unsigned char)*(cp1+1))) {
2103 if (*++cp1 == '0') {
2104 const char *cp3 = src;
2110 else if (toks[toknum =
2112 const char *cp3=tp[toknum];
2126 "nmap: unbalanced brackets.\n",
2134 while (*++cp1 && *cp1 != ']') {
2135 if (*cp1 == '\\' && *(cp1 + 1)) {
2141 "nmap: unbalanced brackets.\n",
2158 if (isdigit((unsigned char)*(cp1 + 1))) {
2159 if (*++cp1 == '0') {
2160 const char *cp3 = src;
2166 else if (toks[toknum = *cp1 - '1']) {
2167 const char *cp3 = tp[toknum];
2169 while (cp3 != te[toknum]) {
2175 /* intentional drop through */
2183 return *dst ? dst : src;
2187 setpassive(int argc, char *argv[])
2191 passivemode = !passivemode;
2192 activefallback = passivemode;
2193 } else if (argc != 2) {
2195 UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
2198 } else if (strcasecmp(argv[1], "on") == 0) {
2201 } else if (strcasecmp(argv[1], "off") == 0) {
2204 } else if (strcasecmp(argv[1], "auto") == 0) {
2209 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
2210 onoff(passivemode), onoff(activefallback));
2216 setepsv4(int argc, char *argv[])
2218 code = togglevar(argc, argv, &epsv4,
2219 verbose ? "EPSV/EPRT on IPv4" : NULL);
2224 setepsv6(int argc, char *argv[])
2226 code = togglevar(argc, argv, &epsv6,
2227 verbose ? "EPSV/EPRT on IPv6" : NULL);
2232 setepsv(int argc, char*argv[])
2234 setepsv4(argc,argv);
2235 setepsv6(argc,argv);
2239 setsunique(int argc, char *argv[])
2242 code = togglevar(argc, argv, &sunique, "Store unique");
2246 setrunique(int argc, char *argv[])
2249 code = togglevar(argc, argv, &runique, "Receive unique");
2253 parserate(int argc, char *argv[], int cmdlineopt)
2255 int dir, max, incr, showonly;
2256 sigfunc oldusr1, oldusr2;
2258 if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
2262 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
2266 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
2270 dir = max = incr = showonly = 0;
2273 #define RATE_ALL (RATE_GET | RATE_PUT)
2275 if (strcasecmp(argv[1], "all") == 0)
2277 else if (strcasecmp(argv[1], "get") == 0)
2279 else if (strcasecmp(argv[1], "put") == 0)
2285 if ((max = strsuftoi(argv[2])) < 0)
2291 if ((incr = strsuftoi(argv[3])) <= 0)
2296 oldusr1 = xsignal(SIGUSR1, SIG_IGN);
2297 oldusr2 = xsignal(SIGUSR2, SIG_IGN);
2298 if (dir & RATE_GET) {
2301 rate_get_incr = incr;
2303 if (!cmdlineopt || verbose)
2305 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
2306 onoff(rate_get), rate_get, rate_get_incr);
2308 if (dir & RATE_PUT) {
2311 rate_put_incr = incr;
2313 if (!cmdlineopt || verbose)
2315 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
2316 onoff(rate_put), rate_put, rate_put_incr);
2318 (void)xsignal(SIGUSR1, oldusr1);
2319 (void)xsignal(SIGUSR2, oldusr2);
2324 setrate(int argc, char *argv[])
2327 code = parserate(argc, argv, 0);
2330 /* change directory to parent directory */
2332 cdup(int argc, char *argv[])
2337 UPRINTF("usage: %s\n", argv[0]);
2341 r = command("CDUP");
2342 if (r == ERROR && code == 500) {
2344 fputs("CDUP command not recognized, trying XCUP.\n",
2346 r = command("XCUP");
2348 if (r == COMPLETE) {
2355 * Restart transfer at specific point
2358 restart(int argc, char *argv[])
2361 if (argc == 0 || argc > 2) {
2362 UPRINTF("usage: %s [restart-point]\n", argv[0]);
2366 if (! features[FEAT_REST_STREAM]) {
2368 "Restart is not supported by the remote server.\n");
2375 rp = STRTOLL(argv[1], &ep, 10);
2376 if (rp < 0 || *ep != '\0')
2377 fprintf(ttyout, "restart: Invalid offset `%s'\n",
2382 if (restart_point == 0)
2383 fputs("No restart point defined.\n", ttyout);
2386 "Restarting at " LLF " for next get, put or append\n",
2387 (LLT)restart_point);
2391 * Show remote system type
2394 syst(int argc, char *argv[])
2396 int oldverbose = verbose;
2399 UPRINTF("usage: %s\n", argv[0]);
2403 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2404 (void)command("SYST");
2405 verbose = oldverbose;
2409 macdef(int argc, char *argv[])
2417 fputs("Limit of 16 macros have already been defined.\n",
2422 if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
2424 UPRINTF("usage: %s macro_name\n", argv[0]);
2430 "Enter macro line by line, terminating it with a null line.\n",
2432 (void)strlcpy(macros[macnum].mac_name, argv[1],
2433 sizeof(macros[macnum].mac_name));
2435 macros[macnum].mac_start = macbuf;
2437 macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
2438 tmp = macros[macnum].mac_start;
2439 while (tmp != macbuf+4096) {
2440 if ((c = getchar()) == EOF) {
2441 fputs("macdef: end of file encountered.\n", ttyout);
2445 if ((*tmp = c) == '\n') {
2446 if (tmp == macros[macnum].mac_start) {
2447 macros[macnum++].mac_end = tmp;
2451 if (*(tmp-1) == '\0') {
2452 macros[macnum++].mac_end = tmp - 1;
2461 while ((c = getchar()) != '\n' && c != EOF)
2463 if (c == EOF || getchar() == '\n') {
2464 fputs("Macro not defined - 4K buffer exceeded.\n",
2473 * Get size of file on remote machine
2476 sizecmd(int argc, char *argv[])
2480 if (argc == 0 || argc > 2 ||
2481 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2482 UPRINTF("usage: %s remote-file\n", argv[0]);
2486 size = remotesize(argv[1], 1);
2489 "%s\t" LLF "\n", argv[1], (LLT)size);
2494 * Get last modification time of file on remote machine
2497 modtime(int argc, char *argv[])
2501 if (argc == 0 || argc > 2 ||
2502 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2503 UPRINTF("usage: %s remote-file\n", argv[0]);
2507 mtime = remotemodtime(argv[1], 1);
2509 fprintf(ttyout, "%s\t%s", argv[1],
2510 rfc2822time(localtime(&mtime)));
2515 * Show status on remote machine
2518 rmtstatus(int argc, char *argv[])
2522 UPRINTF("usage: %s [remote-file]\n", argv[0]);
2526 COMMAND_1ARG(argc, argv, "STAT");
2530 * Get file if modtime is more recent than current file
2533 newer(int argc, char *argv[])
2536 if (getit(argc, argv, -1, "w"))
2538 "Local file \"%s\" is newer than remote file \"%s\".\n",
2543 * Display one local file through $PAGER.
2546 lpage(int argc, char *argv[])
2549 char *p, *pager, *locfile;
2551 if (argc == 0 || argc > 2 ||
2552 (argc == 1 && !another(&argc, &argv, "local-file"))) {
2553 UPRINTF("usage: %s local-file\n", argv[0]);
2557 if ((locfile = globulize(argv[1])) == NULL) {
2561 p = getoptionvalue("pager");
2564 len = strlen(p) + strlen(locfile) + 2;
2565 pager = ftp_malloc(len);
2566 (void)strlcpy(pager, p, len);
2567 (void)strlcat(pager, " ", len);
2568 (void)strlcat(pager, locfile, len);
2572 (void)free(locfile);
2576 * Display one remote file through $PAGER.
2579 page(int argc, char *argv[])
2581 int ohash, orestart_point, overbose;
2585 if (argc == 0 || argc > 2 ||
2586 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2587 UPRINTF("usage: %s remote-file\n", argv[0]);
2591 p = getoptionvalue("pager");
2594 len = strlen(p) + 2;
2595 pager = ftp_malloc(len);
2597 (void)strlcpy(pager + 1, p, len - 1);
2600 orestart_point = restart_point;
2602 hash = restart_point = verbose = 0;
2603 recvrequest("RETR", pager, argv[1], "r+", 1, 0);
2605 restart_point = orestart_point;
2611 * Set the socket send or receive buffer size.
2614 setxferbuf(int argc, char *argv[])
2620 UPRINTF("usage: %s size\n", argv[0]);
2624 if (strcasecmp(argv[0], "sndbuf") == 0)
2626 else if (strcasecmp(argv[0], "rcvbuf") == 0)
2628 else if (strcasecmp(argv[0], "xferbuf") == 0)
2633 if ((size = strsuftoi(argv[1])) == -1)
2637 fprintf(ttyout, "%s: size must be positive.\n", argv[0]);
2645 fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
2646 sndbuf_size, rcvbuf_size);
2651 * Set or display options (defaults are provided by various env vars)
2654 setoption(int argc, char *argv[])
2659 if (argc == 0 || (argc != 1 && argc != 3)) {
2660 UPRINTF("usage: %s [option value]\n", argv[0]);
2664 #define OPTIONINDENT ((int) sizeof("http_proxy"))
2666 for (o = optiontab; o->name != NULL; o++) {
2667 fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT,
2668 o->name, o->value ? o->value : "");
2671 o = getoption(argv[1]);
2673 fprintf(ttyout, "No such option `%s'.\n", argv[1]);
2677 o->value = ftp_strdup(argv[2]);
2679 fprintf(ttyout, "Setting `%s' to `%s'.\n",
2689 unsetoption(int argc, char *argv[])
2694 if (argc == 0 || argc != 2) {
2695 UPRINTF("usage: %s option\n", argv[0]);
2699 o = getoption(argv[1]);
2701 fprintf(ttyout, "No such option `%s'.\n", argv[1]);
2705 fprintf(ttyout, "Unsetting `%s'.\n", o->name);
2710 * Display features supported by the remote host.
2713 feat(int argc, char *argv[])
2715 int oldverbose = verbose;
2718 UPRINTF("usage: %s\n", argv[0]);
2722 if (! features[FEAT_FEAT]) {
2724 "FEAT is not supported by the remote server.\n");
2727 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2728 (void)command("FEAT");
2729 verbose = oldverbose;
2733 mlst(int argc, char *argv[])
2735 int oldverbose = verbose;
2737 if (argc < 1 || argc > 2) {
2738 UPRINTF("usage: %s [remote-path]\n", argv[0]);
2742 if (! features[FEAT_MLST]) {
2744 "MLST is not supported by the remote server.\n");
2747 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2748 COMMAND_1ARG(argc, argv, "MLST");
2749 verbose = oldverbose;
2753 opts(int argc, char *argv[])
2755 int oldverbose = verbose;
2757 if (argc < 2 || argc > 3) {
2758 UPRINTF("usage: %s command [options]\n", argv[0]);
2762 if (! features[FEAT_FEAT]) {
2764 "OPTS is not supported by the remote server.\n");
2767 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2769 command("OPTS %s", argv[1]);
2771 command("OPTS %s %s", argv[1], argv[2]);
2772 verbose = oldverbose;