1 /* $NetBSD: cmds.c,v 1.17 2010/01/12 06:55:47 lukem Exp $ */
2 /* from NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp */
5 * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
13 * NASA Ames Research Center.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1985, 1989, 1993, 1994
39 * The Regents of the University of California. All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * Copyright (C) 1997 and 1998 WIDE Project.
68 * All rights reserved.
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. Neither the name of the project nor the names of its contributors
79 * may be used to endorse or promote products derived from this software
80 * without specific prior written permission.
82 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
86 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99 #include <sys/cdefs.h>
102 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
104 __RCSID(" NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp ");
106 #endif /* not lint */
109 * FTP User Program -- Command Routines.
111 #include <sys/types.h>
112 #include <sys/socket.h>
113 #include <sys/stat.h>
114 #include <sys/wait.h>
115 #include <arpa/ftp.h>
135 static struct types {
141 { "ascii", "A", TYPE_A, 0 },
142 { "binary", "I", TYPE_I, 0 },
143 { "image", "I", TYPE_I, 0 },
144 { "ebcdic", "E", TYPE_E, 0 },
145 { "tenex", "L", TYPE_L, bytename },
146 { NULL, NULL, 0, NULL }
149 static sigjmp_buf jabort;
151 static int confirm(const char *, const char *);
152 static void mintr(int);
153 static void mabort(const char *);
154 static void set_type(const char *);
156 static const char *doprocess(char *, size_t, const char *, int, int, int);
157 static const char *domap(char *, size_t, const char *);
158 static const char *docase(char *, size_t, const char *);
159 static const char *dotrans(char *, size_t, const char *);
162 * Confirm if "cmd" is to be performed upon "file".
163 * If "file" is NULL, generate a "Continue with" prompt instead.
166 confirm(const char *cmd, const char *file)
168 const char *errormsg;
170 const char *promptleft, *promptright;
172 if (!interactive || confirmrest)
175 promptleft = "Continue with";
182 fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright);
183 (void)fflush(ttyout);
184 if (get_line(stdin, cline, sizeof(cline), &errormsg) < 0) {
186 fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd);
189 switch (tolower((unsigned char)*cline)) {
193 "Prompting off for duration of %s.\n", cmd);
197 fputs("Interactive mode: off.\n", ttyout);
201 fprintf(ttyout, "%s aborted.\n", cmd);
207 " confirmation options:\n"
208 "\ta answer `yes' for the duration of %s\n"
209 "\tn answer `no' for this file\n"
210 "\tp turn off `prompt' mode\n"
211 "\tq stop the current %s\n"
212 "\ty answer `yes' for this file\n"
213 "\t? this help list\n",
215 continue; /* back to while(1) */
226 settype(int argc, char *argv[])
230 if (argc == 0 || argc > 2) {
233 UPRINTF("usage: %s [", argv[0]);
235 for (p = types; p->t_name; p++) {
236 fprintf(ttyout, "%s%s", sep, p->t_name);
239 fputs(" ]\n", ttyout);
244 fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
252 set_type(const char *ttype)
257 for (p = types; p->t_name; p++)
258 if (strcmp(ttype, p->t_name) == 0)
260 if (p->t_name == 0) {
261 fprintf(ttyout, "%s: unknown mode.\n", ttype);
265 if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
266 comret = command("TYPE %s %s", p->t_mode, p->t_arg);
268 comret = command("TYPE %s", p->t_mode);
269 if (comret == COMPLETE) {
270 (void)strlcpy(typename, p->t_name, sizeof(typename));
271 curtype = type = p->t_type;
276 * Internal form of settype; changes current type in use with server
277 * without changing our notion of the type for data transfers.
278 * Used to change to and from ascii for listings.
281 changetype(int newtype, int show)
284 int comret, oldverbose = verbose;
288 if (newtype == curtype)
290 if (ftp_debug == 0 && show == 0)
292 for (p = types; p->t_name; p++)
293 if (newtype == p->t_type)
295 if (p->t_name == 0) {
296 errx(1, "changetype: unknown type %d", newtype);
298 if (newtype == TYPE_L && bytename[0] != '\0')
299 comret = command("TYPE %s %s", p->t_mode, bytename);
301 comret = command("TYPE %s", p->t_mode);
302 if (comret == COMPLETE)
304 verbose = oldverbose;
308 * Set binary transfer type.
312 setbinary(int argc, char *argv[])
316 UPRINTF("usage: %s\n", argv[0]);
324 * Set ascii transfer type.
328 setascii(int argc, char *argv[])
332 UPRINTF("usage: %s\n", argv[0]);
340 * Set tenex transfer type.
344 settenex(int argc, char *argv[])
348 UPRINTF("usage: %s\n", argv[0]);
356 * Set file transfer mode.
360 setftmode(int argc, char *argv[])
364 UPRINTF("usage: %s mode-name\n", argv[0]);
368 fprintf(ttyout, "We only support %s mode, sorry.\n", modename);
373 * Set file transfer format.
377 setform(int argc, char *argv[])
381 UPRINTF("usage: %s format\n", argv[0]);
385 fprintf(ttyout, "We only support %s format, sorry.\n", formname);
390 * Set file transfer structure.
394 setstruct(int argc, char *argv[])
398 UPRINTF("usage: %s struct-mode\n", argv[0]);
402 fprintf(ttyout, "We only support %s structure, sorry.\n", structname);
407 * Send a single file.
410 put(int argc, char *argv[])
412 char buf[MAXPATHLEN];
423 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file")))
425 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
427 UPRINTF("usage: %s local-file [remote-file]\n", argv[0]);
431 if ((locfile = globulize(argv[1])) == NULL) {
436 if (loc) /* If argv[2] is a copy of the old argv[1], update it */
438 cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
439 remfile = doprocess(buf, sizeof(buf), remfile,
440 0, loc && ntflag, loc && mapflag);
441 sendrequest(cmd, locfile, remfile,
442 locfile != argv[1] || remfile != argv[2]);
447 doprocess(char *dst, size_t dlen, const char *src,
448 int casef, int transf, int mapf)
451 src = docase(dst, dlen, src);
453 src = dotrans(dst, dlen, src);
455 src = domap(dst, dlen, src);
460 * Send multiple files.
463 mput(int argc, char *argv[])
470 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
471 UPRINTF("usage: %s local-files\n", argv[0]);
476 oldintr = xsignal(SIGINT, mintr);
477 if (sigsetjmp(jabort, 1))
482 while ((cp = remglob(argv, 0, NULL)) != NULL) {
483 if (*cp == '\0' || !connected) {
487 if (mflag && confirm(argv[0], cp)) {
488 char buf[MAXPATHLEN];
489 tp = doprocess(buf, sizeof(buf), cp,
490 mcase, ntflag, mapflag);
491 sendrequest((sunique) ? "STOU" : "STOR",
492 cp, tp, cp != tp || !interactive);
493 if (!mflag && fromatty) {
494 ointer = interactive;
496 if (confirm(argv[0], NULL)) {
499 interactive = ointer;
505 for (i = 1; i < argc && connected; i++) {
511 if (mflag && confirm(argv[0], argv[i])) {
512 char buf[MAXPATHLEN];
513 tp = doprocess(buf, sizeof(buf), argv[i],
515 sendrequest((sunique) ? "STOU" : "STOR",
516 argv[i], tp, tp != argv[i] || !interactive);
517 if (!mflag && fromatty) {
518 ointer = interactive;
520 if (confirm(argv[0], NULL)) {
523 interactive = ointer;
529 memset(&gl, 0, sizeof(gl));
530 flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
531 if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
532 warnx("Glob pattern `%s' not found", argv[i]);
536 for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
538 if (mflag && confirm(argv[0], *cpp)) {
539 char buf[MAXPATHLEN];
541 tp = doprocess(buf, sizeof(buf), *cpp,
543 sendrequest((sunique) ? "STOU" : "STOR",
544 *cpp, tp, *cpp != tp || !interactive);
545 if (!mflag && fromatty) {
546 ointer = interactive;
548 if (confirm(argv[0], NULL)) {
551 interactive = ointer;
558 (void)xsignal(SIGINT, oldintr);
563 reget(int argc, char *argv[])
566 (void)getit(argc, argv, 1, "r+");
570 get(int argc, char *argv[])
573 (void)getit(argc, argv, 0, restart_point ? "r+" : "w" );
578 * If restartit is 1, restart the xfer always.
579 * If restartit is -1, restart the xfer only if the remote file is newer.
582 getit(int argc, char *argv[], int restartit, const char *gmode)
585 char *remfile, *olocfile;
587 char buf[MAXPATHLEN];
595 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file")))
597 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
599 UPRINTF("usage: %s remote-file [local-file]\n", argv[0]);
604 if ((olocfile = globulize(argv[2])) == NULL) {
608 locfile = doprocess(buf, sizeof(buf), olocfile,
609 loc && mcase, loc && ntflag, loc && mapflag);
614 if (! features[FEAT_REST_STREAM]) {
616 "Restart is not supported by the remote server.\n");
619 ret = stat(locfile, &stbuf);
620 if (restartit == 1) {
622 warn("Can't stat `%s'", locfile);
625 restart_point = stbuf.st_size;
630 mtime = remotemodtime(argv[1], 0);
633 if (stbuf.st_mtime >= mtime) {
641 recvrequest("RETR", locfile, remfile, gmode,
642 remfile != argv[1] || locfile != argv[2], loc);
645 (void)free(olocfile);
656 write(fileno(ttyout), "\n", 1);
657 siglongjmp(jabort, 1);
661 mabort(const char *cmd)
665 if (mflag && fromatty) {
666 ointer = interactive;
670 if (confirm(cmd, NULL)) {
671 interactive = ointer;
675 interactive = ointer;
682 * Get multiple files.
685 mget(int argc, char *argv[])
691 int volatile restartit;
694 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
695 UPRINTF("usage: %s remote-files\n", argv[0]);
702 if (strcmp(argv[0], "mreget") == 0) {
703 if (! features[FEAT_REST_STREAM]) {
705 "Restart is not supported by the remote server.\n");
710 oldintr = xsignal(SIGINT, mintr);
711 if (sigsetjmp(jabort, 1))
713 while ((cp = remglob(argv, proxy, NULL)) != NULL) {
714 char buf[MAXPATHLEN];
715 if (*cp == '\0' || !connected) {
721 if (! fileindir(cp, localcwd)) {
722 fprintf(ttyout, "Skipping non-relative filename `%s'\n",
726 if (!confirm(argv[0], cp))
728 tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag);
732 if (stat(tp, &stbuf) == 0)
733 restart_point = stbuf.st_size;
735 warn("Can't stat `%s'", tp);
737 recvrequest("RETR", tp, cp, restart_point ? "r+" : "w",
738 tp != cp || !interactive, 1);
740 if (!mflag && fromatty) {
741 ointer = interactive;
743 if (confirm(argv[0], NULL))
745 interactive = ointer;
748 (void)xsignal(SIGINT, oldintr);
753 * Read list of filenames from a local file and get those
756 fget(int argc, char *argv[])
760 char buf[MAXPATHLEN], cmdbuf[MAX_C_NAME];
763 UPRINTF("usage: %s localfile\n", argv[0]);
768 fp = fopen(argv[1], "r");
770 fprintf(ttyout, "Can't open source file %s\n", argv[1]);
775 (void)strlcpy(cmdbuf, "get", sizeof(cmdbuf));
777 gmode = restart_point ? "r+" : "w";
779 while (get_line(fp, buf, sizeof(buf), NULL) >= 0) {
783 (void)getit(argc, argv, 0, gmode);
792 return (val ? "on" : "off");
800 status(int argc, char *argv[])
804 UPRINTF("usage: %s\n", argv[0]);
810 fprintf(ttyout, "Connected %sto %s.\n",
811 connected == -1 ? "and logged in" : "", hostname);
813 fputs("Not connected.\n", ttyout);
817 fprintf(ttyout, "Connected for proxy commands to %s.\n",
821 fputs("No proxy connection.\n", ttyout);
825 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
826 *gateserver ? gateserver : "(none)", gateport);
827 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
828 onoff(passivemode), onoff(activefallback));
829 fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
830 modename, typename, formname, structname);
831 fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
832 onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob));
833 fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n",
834 onoff(sunique), onoff(runique));
835 fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve));
836 fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase),
839 fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout);
842 fputs("Ntrans: off.\n", ttyout);
845 fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout);
848 fputs("Nmap: off.\n", ttyout);
851 "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
852 onoff(hash), mark, onoff(progress));
854 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
855 onoff(rate_get), rate_get, rate_get_incr);
857 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
858 onoff(rate_put), rate_put, rate_put_incr);
860 "Socket buffer sizes: send %d, receive %d.\n",
861 sndbuf_size, rcvbuf_size);
862 fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
863 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
864 epsv4bad ? " (disabled for this connection)" : "");
865 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv6: %s%s.\n", onoff(epsv6),
866 epsv6bad ? " (disabled for this connection)" : "");
867 fprintf(ttyout, "Command line editing: %s.\n",
868 #ifdef NO_EDITCOMPLETE
869 "support not compiled in"
870 #else /* !def NO_EDITCOMPLETE */
872 #endif /* !def NO_EDITCOMPLETE */
877 fputs("Macros:\n", ttyout);
878 for (i=0; i<macnum; i++) {
879 fprintf(ttyout, "\t%s\n", macros[i].mac_name);
882 #endif /* !def NO_STATUS */
883 fprintf(ttyout, "Version: %s %s\n", FTP_PRODUCT, FTP_VERSION);
891 togglevar(int argc, char *argv[], int *var, const char *mesg)
895 } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
897 } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
900 UPRINTF("usage: %s [ on | off ]\n", argv[0]);
904 fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
909 * Set beep on cmd completed mode.
913 setbell(int argc, char *argv[])
916 code = togglevar(argc, argv, &bell, "Bell mode");
920 * Set command line editing
924 setedit(int argc, char *argv[])
927 #ifdef NO_EDITCOMPLETE
929 UPRINTF("usage: %s\n", argv[0]);
934 fputs("Editing support not compiled in; ignoring command.\n",
936 #else /* !def NO_EDITCOMPLETE */
937 code = togglevar(argc, argv, &editing, "Editing mode");
939 #endif /* !def NO_EDITCOMPLETE */
943 * Turn on packet tracing.
947 settrace(int argc, char *argv[])
950 code = togglevar(argc, argv, &trace, "Packet tracing");
954 * Toggle hash mark printing during transfers, or set hash mark bytecount.
958 sethash(int argc, char *argv[])
962 else if (argc != 2) {
963 UPRINTF("usage: %s [ on | off | bytecount ]\n",
967 } else if (strcasecmp(argv[1], "on") == 0)
969 else if (strcasecmp(argv[1], "off") == 0)
974 nmark = strsuftoi(argv[1]);
976 fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
984 fprintf(ttyout, "Hash mark printing %s", onoff(hash));
986 fprintf(ttyout, " (%d bytes/hash mark)", mark);
987 fputs(".\n", ttyout);
994 * Turn on printing of server echo's.
998 setverbose(int argc, char *argv[])
1001 code = togglevar(argc, argv, &verbose, "Verbose mode");
1005 * Toggle PORT/LPRT cmd use before each data connection.
1009 setport(int argc, char *argv[])
1012 code = togglevar(argc, argv, &sendport, "Use of PORT/LPRT cmds");
1016 * Toggle transfer progress bar.
1020 setprogress(int argc, char *argv[])
1023 code = togglevar(argc, argv, &progress, "Progress bar");
1029 * Turn on interactive prompting during mget, mput, and mdelete.
1033 setprompt(int argc, char *argv[])
1036 code = togglevar(argc, argv, &interactive, "Interactive mode");
1040 * Toggle gate-ftp mode, or set gate-ftp server
1044 setgate(int argc, char *argv[])
1046 static char gsbuf[MAXHOSTNAMELEN];
1048 if (argc == 0 || argc > 3) {
1050 "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
1053 } else if (argc < 2) {
1054 gatemode = !gatemode;
1056 if (argc == 2 && strcasecmp(argv[1], "on") == 0)
1058 else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
1062 gateport = ftp_strdup(argv[2]);
1063 (void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
1068 if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
1070 "Disabling gate-ftp mode - no gate-ftp server defined.\n");
1073 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n",
1074 onoff(gatemode), *gateserver ? gateserver : "(none)",
1081 * Toggle metacharacter interpretation on local file names.
1085 setglob(int argc, char *argv[])
1088 code = togglevar(argc, argv, &doglob, "Globbing");
1092 * Toggle preserving modification times on retrieved files.
1096 setpreserve(int argc, char *argv[])
1099 code = togglevar(argc, argv, &preserve, "Preserve modification times");
1103 * Set debugging mode on/off and/or set level of debugging.
1107 setdebug(int argc, char *argv[])
1109 if (argc == 0 || argc > 2) {
1110 UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
1113 } else if (argc == 2) {
1114 if (strcasecmp(argv[1], "on") == 0)
1116 else if (strcasecmp(argv[1], "off") == 0)
1121 val = strsuftoi(argv[1]);
1123 fprintf(ttyout, "%s: bad debugging value.\n",
1131 ftp_debug = !ftp_debug;
1133 options |= SO_DEBUG;
1135 options &= ~SO_DEBUG;
1136 fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
1137 code = ftp_debug > 0;
1141 * Set current working directory on remote machine.
1144 cd(int argc, char *argv[])
1148 if (argc == 0 || argc > 2 ||
1149 (argc == 1 && !another(&argc, &argv, "remote-directory"))) {
1150 UPRINTF("usage: %s remote-directory\n", argv[0]);
1154 r = command("CWD %s", argv[1]);
1155 if (r == ERROR && code == 500) {
1157 fputs("CWD command not recognized, trying XCWD.\n",
1159 r = command("XCWD %s", argv[1]);
1161 if (r == COMPLETE) {
1168 * Set current working directory on local machine.
1171 lcd(int argc, char *argv[])
1178 argv[1] = localhome;
1181 UPRINTF("usage: %s [local-directory]\n", argv[0]);
1184 if ((locdir = globulize(argv[1])) == NULL)
1186 if (chdir(locdir) == -1)
1187 warn("Can't chdir `%s'", locdir);
1191 fprintf(ttyout, "Local directory now: %s\n", localcwd);
1194 fprintf(ttyout, "Unable to determine local directory\n");
1201 * Delete a single file.
1204 delete(int argc, char *argv[])
1207 if (argc == 0 || argc > 2 ||
1208 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
1209 UPRINTF("usage: %s remote-file\n", argv[0]);
1213 if (command("DELE %s", argv[1]) == COMPLETE)
1218 * Delete multiple files.
1221 mdelete(int argc, char *argv[])
1228 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
1229 UPRINTF("usage: %s [remote-files]\n", argv[0]);
1234 oldintr = xsignal(SIGINT, mintr);
1235 if (sigsetjmp(jabort, 1))
1237 while ((cp = remglob(argv, 0, NULL)) != NULL) {
1242 if (mflag && confirm(argv[0], cp)) {
1243 if (command("DELE %s", cp) == COMPLETE)
1245 if (!mflag && fromatty) {
1246 ointer = interactive;
1248 if (confirm(argv[0], NULL)) {
1251 interactive = ointer;
1255 (void)xsignal(SIGINT, oldintr);
1260 * Rename a remote file.
1263 renamefile(int argc, char *argv[])
1266 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name")))
1268 if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
1270 UPRINTF("usage: %s from-name to-name\n", argv[0]);
1274 if (command("RNFR %s", argv[1]) == CONTINUE &&
1275 command("RNTO %s", argv[2]) == COMPLETE)
1280 * Get a directory listing of remote files.
1281 * Supports being invoked as:
1287 * pdir, pls LIST |$PAGER
1288 * pmlsd MLSD |$PAGER
1291 ls(int argc, char *argv[])
1294 char *remdir, *locbuf;
1295 const char *locfile;
1296 int pagecmd, mlsdcmd;
1301 pagecmd = mlsdcmd = 0;
1303 * the only commands that start with `p' are
1304 * the `pager' versions.
1306 if (argv[0][0] == 'p')
1308 if (strcmp(argv[0] + pagecmd , "mlsd") == 0) {
1309 if (! features[FEAT_MLST]) {
1311 "MLSD is not supported by the remote server.\n");
1321 else if (strcmp(argv[0] + pagecmd, "nlist") == 0)
1330 if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
1332 if (pagecmd || mlsdcmd)
1333 UPRINTF("usage: %s [remote-path]\n", argv[0]);
1335 UPRINTF("usage: %s [remote-path [local-file]]\n",
1345 p = getoptionvalue("pager");
1348 len = strlen(p) + 2;
1349 locbuf = ftp_malloc(len);
1351 (void)strlcpy(locbuf + 1, p, len - 1);
1353 } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
1354 if ((locbuf = globulize(locfile)) == NULL ||
1355 !confirm("output to local-file:", locbuf)) {
1361 recvrequest(cmd, locfile, remdir, "w", 0, 0);
1368 * Get a directory listing of multiple remote files.
1371 mls(int argc, char *argv[])
1375 int volatile dolist;
1376 char * volatile dest, *odest;
1381 if (argc < 2 && !another(&argc, &argv, "remote-files"))
1383 if (argc < 3 && !another(&argc, &argv, "local-file")) {
1385 UPRINTF("usage: %s remote-files local-file\n", argv[0]);
1389 odest = dest = argv[argc - 1];
1390 argv[argc - 1] = NULL;
1391 if (strcmp(dest, "-") && *dest != '|')
1392 if (((dest = globulize(dest)) == NULL) ||
1393 !confirm("output to local-file:", dest)) {
1397 dolist = strcmp(argv[0], "mls");
1399 oldintr = xsignal(SIGINT, mintr);
1400 if (sigsetjmp(jabort, 1))
1402 for (i = 1; mflag && i < argc-1 && connected; i++) {
1403 lmode = (i == 1) ? "w" : "a";
1404 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], lmode,
1406 if (!mflag && fromatty) {
1407 ointer = interactive;
1409 if (confirm(argv[0], NULL)) {
1412 interactive = ointer;
1415 (void)xsignal(SIGINT, oldintr);
1417 if (dest != odest) /* free up after globulize() */
1426 shell(int argc, char *argv[])
1430 char shellnam[MAXPATHLEN];
1431 const char *shellp, *namep;
1435 UPRINTF("usage: %s [command [args]]\n", argv[0]);
1439 oldintr = xsignal(SIGINT, SIG_IGN);
1440 if ((pid = fork()) == 0) {
1441 for (pid = 3; pid < 20; pid++)
1443 (void)xsignal(SIGINT, SIG_DFL);
1444 shellp = getenv("SHELL");
1446 shellp = _PATH_BSHELL;
1447 namep = strrchr(shellp, '/');
1452 (void)strlcpy(shellnam, namep, sizeof(shellnam));
1454 fputs(shellp, ttyout);
1458 execl(shellp, shellnam, "-c", altarg, (char *)0);
1461 execl(shellp, shellnam, (char *)0);
1463 warn("Can't execute `%s'", shellp);
1468 while (wait(&wait_status) != pid)
1470 (void)xsignal(SIGINT, oldintr);
1472 warn("Can't fork a subshell; try again later");
1479 * Send new user information (re-login)
1482 user(int argc, char *argv[])
1485 char emptypass[] = "";
1491 (void)another(&argc, &argv, "username");
1492 if (argc < 2 || argc > 4) {
1494 UPRINTF("usage: %s username [password [account]]\n",
1499 n = command("USER %s", argv[1]);
1500 if (n == CONTINUE) {
1502 password = getpass("Password: ");
1503 if (password == NULL)
1504 password = emptypass;
1508 n = command("PASS %s", password);
1509 memset(password, 0, strlen(password));
1511 if (n == CONTINUE) {
1514 password = getpass("Account: ");
1515 if (password == NULL)
1516 password = emptypass;
1520 n = command("ACCT %s", password);
1521 memset(password, 0, strlen(password));
1523 if (n != COMPLETE) {
1524 fputs("Login failed.\n", ttyout);
1527 if (!aflag && argc == 4) {
1529 (void)command("ACCT %s", password);
1530 memset(password, 0, strlen(password));
1537 * Print working directory on remote machine.
1541 pwd(int argc, char *argv[])
1546 UPRINTF("usage: %s\n", argv[0]);
1552 fprintf(ttyout, "Unable to determine remote directory\n");
1554 fprintf(ttyout, "Remote directory: %s\n", remotecwd);
1560 * Print working directory on local machine.
1563 lpwd(int argc, char *argv[])
1568 UPRINTF("usage: %s\n", argv[0]);
1574 fprintf(ttyout, "Unable to determine local directory\n");
1576 fprintf(ttyout, "Local directory: %s\n", localcwd);
1585 makedir(int argc, char *argv[])
1589 if (argc == 0 || argc > 2 ||
1590 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1591 UPRINTF("usage: %s directory-name\n", argv[0]);
1595 r = command("MKD %s", argv[1]);
1596 if (r == ERROR && code == 500) {
1598 fputs("MKD command not recognized, trying XMKD.\n",
1600 r = command("XMKD %s", argv[1]);
1607 * Remove a directory.
1610 removedir(int argc, char *argv[])
1614 if (argc == 0 || argc > 2 ||
1615 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1616 UPRINTF("usage: %s directory-name\n", argv[0]);
1620 r = command("RMD %s", argv[1]);
1621 if (r == ERROR && code == 500) {
1623 fputs("RMD command not recognized, trying XRMD.\n",
1625 r = command("XRMD %s", argv[1]);
1632 * Send a line, verbatim, to the remote machine.
1635 quote(int argc, char *argv[])
1639 (argc == 1 && !another(&argc, &argv, "command line to send"))) {
1640 UPRINTF("usage: %s line-to-send\n", argv[0]);
1644 quote1("", argc, argv);
1648 * Send a SITE command to the remote machine. The line
1649 * is sent verbatim to the remote machine, except that the
1650 * word "SITE" is added at the front.
1653 site(int argc, char *argv[])
1657 (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
1658 UPRINTF("usage: %s line-to-send\n", argv[0]);
1662 quote1("SITE ", argc, argv);
1666 * Turn argv[1..argc) into a space-separated string, then prepend initial text.
1667 * Send the result as a one-line command and get response.
1670 quote1(const char *initial, int argc, char *argv[])
1673 char buf[BUFSIZ]; /* must be >= sizeof(line) */
1675 (void)strlcpy(buf, initial, sizeof(buf));
1676 for (i = 1; i < argc; i++) {
1677 (void)strlcat(buf, argv[i], sizeof(buf));
1679 (void)strlcat(buf, " ", sizeof(buf));
1681 if (command("%s", buf) == PRELIM) {
1682 while (getreply(0) == PRELIM)
1689 do_chmod(int argc, char *argv[])
1692 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode")))
1694 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
1696 UPRINTF("usage: %s mode remote-file\n", argv[0]);
1700 (void)command("SITE CHMOD %s %s", argv[1], argv[2]);
1703 #define COMMAND_1ARG(argc, argv, cmd) \
1707 command(cmd " %s", argv[1])
1710 do_umask(int argc, char *argv[])
1712 int oldverbose = verbose;
1715 UPRINTF("usage: %s [umask]\n", argv[0]);
1720 COMMAND_1ARG(argc, argv, "SITE UMASK");
1721 verbose = oldverbose;
1725 idlecmd(int argc, char *argv[])
1727 int oldverbose = verbose;
1729 if (argc < 1 || argc > 2) {
1730 UPRINTF("usage: %s [seconds]\n", argv[0]);
1735 COMMAND_1ARG(argc, argv, "SITE IDLE");
1736 verbose = oldverbose;
1740 * Ask the other side for help.
1743 rmthelp(int argc, char *argv[])
1745 int oldverbose = verbose;
1748 UPRINTF("usage: %s\n", argv[0]);
1753 COMMAND_1ARG(argc, argv, "HELP");
1754 verbose = oldverbose;
1758 * Terminate session and exit.
1759 * May be called with 0, NULL.
1763 quit(int argc, char *argv[])
1766 /* this may be called with argc == 0, argv == NULL */
1767 if (argc == 0 && argv != NULL) {
1768 UPRINTF("usage: %s\n", argv[0]);
1773 disconnect(0, NULL);
1776 disconnect(0, NULL);
1781 * Terminate session, but don't exit.
1782 * May be called with 0, NULL.
1785 disconnect(int argc, char *argv[])
1788 /* this may be called with argc == 0, argv == NULL */
1789 if (argc == 0 && argv != NULL) {
1790 UPRINTF("usage: %s\n", argv[0]);
1796 (void)command("QUIT");
1801 account(int argc, char *argv[])
1804 char emptypass[] = "";
1806 if (argc == 0 || argc > 2) {
1807 UPRINTF("usage: %s [password]\n", argv[0]);
1814 ap = getpass("Account:");
1818 (void)command("ACCT %s", ap);
1819 memset(ap, 0, strlen(ap));
1822 sigjmp_buf abortprox;
1825 proxabort(int notused)
1840 siglongjmp(abortprox, 1);
1844 doproxy(int argc, char *argv[])
1849 char cmdbuf[MAX_C_NAME];
1851 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
1852 UPRINTF("usage: %s command\n", argv[0]);
1856 c = getcmd(argv[1]);
1857 if (c == (struct cmd *) -1) {
1858 fputs("?Ambiguous command.\n", ttyout);
1863 fputs("?Invalid command.\n", ttyout);
1868 fputs("?Invalid proxy command.\n", ttyout);
1872 if (sigsetjmp(abortprox, 1)) {
1876 oldintr = xsignal(SIGINT, proxabort);
1878 if (c->c_conn && !connected) {
1879 fputs("Not connected.\n", ttyout);
1881 (void)xsignal(SIGINT, oldintr);
1885 cmdpos = strcspn(line, " \t");
1886 if (cmdpos > 0) /* remove leading "proxy " from input buffer */
1887 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
1888 (void)strlcpy(cmdbuf, c->c_name, sizeof(cmdbuf));
1890 (*c->c_handler)(argc-1, argv+1);
1898 (void)xsignal(SIGINT, oldintr);
1902 setcase(int argc, char *argv[])
1905 code = togglevar(argc, argv, &mcase, "Case mapping");
1909 * convert the given name to lower case if it's all upper case, into
1910 * a static buffer which is returned to the caller
1913 docase(char *dst, size_t dlen, const char *src)
1918 for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
1920 if (islower((unsigned char)dst[i]))
1926 for (i = 0; dst[i] != '\0'; i++)
1927 if (isupper((unsigned char)dst[i]))
1928 dst[i] = tolower((unsigned char)dst[i]);
1934 setcr(int argc, char *argv[])
1937 code = togglevar(argc, argv, &crflag, "Carriage Return stripping");
1941 setntrans(int argc, char *argv[])
1944 if (argc == 0 || argc > 3) {
1945 UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
1951 fputs("Ntrans off.\n", ttyout);
1957 (void)strlcpy(ntin, argv[1], sizeof(ntin));
1962 (void)strlcpy(ntout, argv[2], sizeof(ntout));
1966 dotrans(char *dst, size_t dlen, const char *src)
1972 for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
1974 for (cp1 = src; *cp1; cp1++) {
1976 for (i = 0; *(ntin + i) && i < 16; i++) {
1977 if (*cp1 == *(ntin + i)) {
1980 *cp2++ = *(ntout + i);
1981 if (cp2 - dst >= (ptrdiff_t)(dlen - 1))
1997 setnmap(int argc, char *argv[])
2003 fputs("Nmap off.\n", ttyout);
2008 (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
2009 UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
2015 cp = strchr(altarg, ' ');
2020 cp = strchr(altarg, ' ');
2023 (void)strlcpy(mapin, altarg, MAXPATHLEN);
2024 while (*++cp == ' ')
2026 (void)strlcpy(mapout, cp, MAXPATHLEN);
2030 domap(char *dst, size_t dlen, const char *src)
2032 const char *cp1 = src;
2034 const char *tp[9], *te[9];
2035 int i, toks[9], toknum = 0, match = 1;
2037 for (i=0; i < 9; ++i) {
2040 while (match && *cp1 && *cp2) {
2043 if (*++cp2 != *cp1) {
2048 if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
2049 if (*cp1 != *(++cp2+1)) {
2050 toks[toknum = *cp2 - '1']++;
2052 while (*++cp1 && *(cp2+1)
2066 if (match && *cp1) {
2069 if (match && *cp2) {
2073 if (!match && *cp1) /* last token mismatch */
2090 if (*++cp1 == '$' &&
2091 isdigit((unsigned char)*(cp1+1))) {
2092 if (*++cp1 == '0') {
2093 const char *cp3 = src;
2100 else if (toks[toknum = *cp1 - '1']) {
2101 const char *cp3 = tp[toknum];
2103 while (cp3 != te[toknum]) {
2110 while (*cp1 && *cp1 != ',' &&
2115 else if (*cp1 == '$' &&
2116 isdigit((unsigned char)*(cp1+1))) {
2117 if (*++cp1 == '0') {
2118 const char *cp3 = src;
2124 else if (toks[toknum =
2126 const char *cp3=tp[toknum];
2140 "nmap: unbalanced brackets.\n",
2148 while (*++cp1 && *cp1 != ']') {
2149 if (*cp1 == '\\' && *(cp1 + 1)) {
2155 "nmap: unbalanced brackets.\n",
2172 if (isdigit((unsigned char)*(cp1 + 1))) {
2173 if (*++cp1 == '0') {
2174 const char *cp3 = src;
2180 else if (toks[toknum = *cp1 - '1']) {
2181 const char *cp3 = tp[toknum];
2183 while (cp3 != te[toknum]) {
2189 /* intentional drop through */
2197 return *dst ? dst : src;
2201 setpassive(int argc, char *argv[])
2205 passivemode = !passivemode;
2206 activefallback = passivemode;
2207 } else if (argc != 2) {
2209 UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
2212 } else if (strcasecmp(argv[1], "on") == 0) {
2215 } else if (strcasecmp(argv[1], "off") == 0) {
2218 } else if (strcasecmp(argv[1], "auto") == 0) {
2223 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
2224 onoff(passivemode), onoff(activefallback));
2230 setepsv4(int argc, char *argv[])
2232 code = togglevar(argc, argv, &epsv4,
2233 verbose ? "EPSV/EPRT on IPv4" : NULL);
2238 setepsv6(int argc, char *argv[])
2240 code = togglevar(argc, argv, &epsv6,
2241 verbose ? "EPSV/EPRT on IPv6" : NULL);
2246 setepsv(int argc, char*argv[])
2248 setepsv4(argc,argv);
2249 setepsv6(argc,argv);
2253 setsunique(int argc, char *argv[])
2256 code = togglevar(argc, argv, &sunique, "Store unique");
2260 setrunique(int argc, char *argv[])
2263 code = togglevar(argc, argv, &runique, "Receive unique");
2267 parserate(int argc, char *argv[], int cmdlineopt)
2269 int dir, max, incr, showonly;
2270 sigfunc oldusr1, oldusr2;
2272 if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
2276 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
2280 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
2284 dir = max = incr = showonly = 0;
2287 #define RATE_ALL (RATE_GET | RATE_PUT)
2289 if (strcasecmp(argv[1], "all") == 0)
2291 else if (strcasecmp(argv[1], "get") == 0)
2293 else if (strcasecmp(argv[1], "put") == 0)
2299 if ((max = strsuftoi(argv[2])) < 0)
2305 if ((incr = strsuftoi(argv[3])) <= 0)
2310 oldusr1 = xsignal(SIGUSR1, SIG_IGN);
2311 oldusr2 = xsignal(SIGUSR2, SIG_IGN);
2312 if (dir & RATE_GET) {
2315 rate_get_incr = incr;
2317 if (!cmdlineopt || verbose)
2319 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
2320 onoff(rate_get), rate_get, rate_get_incr);
2322 if (dir & RATE_PUT) {
2325 rate_put_incr = incr;
2327 if (!cmdlineopt || verbose)
2329 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
2330 onoff(rate_put), rate_put, rate_put_incr);
2332 (void)xsignal(SIGUSR1, oldusr1);
2333 (void)xsignal(SIGUSR2, oldusr2);
2338 setrate(int argc, char *argv[])
2341 code = parserate(argc, argv, 0);
2344 /* change directory to parent directory */
2346 cdup(int argc, char *argv[])
2351 UPRINTF("usage: %s\n", argv[0]);
2355 r = command("CDUP");
2356 if (r == ERROR && code == 500) {
2358 fputs("CDUP command not recognized, trying XCUP.\n",
2360 r = command("XCUP");
2362 if (r == COMPLETE) {
2369 * Restart transfer at specific point
2372 restart(int argc, char *argv[])
2375 if (argc == 0 || argc > 2) {
2376 UPRINTF("usage: %s [restart-point]\n", argv[0]);
2380 if (! features[FEAT_REST_STREAM]) {
2382 "Restart is not supported by the remote server.\n");
2389 rp = STRTOLL(argv[1], &ep, 10);
2390 if (rp < 0 || *ep != '\0')
2391 fprintf(ttyout, "restart: Invalid offset `%s'\n",
2396 if (restart_point == 0)
2397 fputs("No restart point defined.\n", ttyout);
2400 "Restarting at " LLF " for next get, put or append\n",
2401 (LLT)restart_point);
2405 * Show remote system type
2408 syst(int argc, char *argv[])
2410 int oldverbose = verbose;
2413 UPRINTF("usage: %s\n", argv[0]);
2417 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2418 (void)command("SYST");
2419 verbose = oldverbose;
2423 macdef(int argc, char *argv[])
2431 fputs("Limit of 16 macros have already been defined.\n",
2436 if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
2438 UPRINTF("usage: %s macro_name\n", argv[0]);
2444 "Enter macro line by line, terminating it with a null line.\n",
2446 (void)strlcpy(macros[macnum].mac_name, argv[1],
2447 sizeof(macros[macnum].mac_name));
2449 macros[macnum].mac_start = macbuf;
2451 macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
2452 tmp = macros[macnum].mac_start;
2453 while (tmp != macbuf+4096) {
2454 if ((c = getchar()) == EOF) {
2455 fputs("macdef: end of file encountered.\n", ttyout);
2459 if ((*tmp = c) == '\n') {
2460 if (tmp == macros[macnum].mac_start) {
2461 macros[macnum++].mac_end = tmp;
2465 if (*(tmp-1) == '\0') {
2466 macros[macnum++].mac_end = tmp - 1;
2475 while ((c = getchar()) != '\n' && c != EOF)
2477 if (c == EOF || getchar() == '\n') {
2478 fputs("Macro not defined - 4K buffer exceeded.\n",
2487 * Get size of file on remote machine
2490 sizecmd(int argc, char *argv[])
2494 if (argc == 0 || argc > 2 ||
2495 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2496 UPRINTF("usage: %s remote-file\n", argv[0]);
2500 size = remotesize(argv[1], 1);
2503 "%s\t" LLF "\n", argv[1], (LLT)size);
2508 * Get last modification time of file on remote machine
2511 modtime(int argc, char *argv[])
2515 if (argc == 0 || argc > 2 ||
2516 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2517 UPRINTF("usage: %s remote-file\n", argv[0]);
2521 mtime = remotemodtime(argv[1], 1);
2523 fprintf(ttyout, "%s\t%s", argv[1],
2524 rfc2822time(localtime(&mtime)));
2529 * Show status on remote machine
2532 rmtstatus(int argc, char *argv[])
2536 UPRINTF("usage: %s [remote-file]\n", argv[0]);
2540 COMMAND_1ARG(argc, argv, "STAT");
2544 * Get file if modtime is more recent than current file
2547 newer(int argc, char *argv[])
2550 if (getit(argc, argv, -1, "w"))
2552 "Local file \"%s\" is newer than remote file \"%s\".\n",
2557 * Display one local file through $PAGER.
2560 lpage(int argc, char *argv[])
2564 char *pager, *locfile;
2566 if (argc == 0 || argc > 2 ||
2567 (argc == 1 && !another(&argc, &argv, "local-file"))) {
2568 UPRINTF("usage: %s local-file\n", argv[0]);
2572 if ((locfile = globulize(argv[1])) == NULL) {
2576 p = getoptionvalue("pager");
2579 len = strlen(p) + strlen(locfile) + 2;
2580 pager = ftp_malloc(len);
2581 (void)strlcpy(pager, p, len);
2582 (void)strlcat(pager, " ", len);
2583 (void)strlcat(pager, locfile, len);
2587 (void)free(locfile);
2591 * Display one remote file through $PAGER.
2594 page(int argc, char *argv[])
2596 int ohash, orestart_point, overbose;
2601 if (argc == 0 || argc > 2 ||
2602 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2603 UPRINTF("usage: %s remote-file\n", argv[0]);
2607 p = getoptionvalue("pager");
2610 len = strlen(p) + 2;
2611 pager = ftp_malloc(len);
2613 (void)strlcpy(pager + 1, p, len - 1);
2616 orestart_point = restart_point;
2618 hash = restart_point = verbose = 0;
2619 recvrequest("RETR", pager, argv[1], "r+", 1, 0);
2621 restart_point = orestart_point;
2627 * Set the socket send or receive buffer size.
2630 setxferbuf(int argc, char *argv[])
2636 UPRINTF("usage: %s size\n", argv[0]);
2640 if (strcasecmp(argv[0], "sndbuf") == 0)
2642 else if (strcasecmp(argv[0], "rcvbuf") == 0)
2644 else if (strcasecmp(argv[0], "xferbuf") == 0)
2649 if ((size = strsuftoi(argv[1])) == -1)
2653 fprintf(ttyout, "%s: size must be positive.\n", argv[0]);
2661 fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
2662 sndbuf_size, rcvbuf_size);
2667 * Set or display options (defaults are provided by various env vars)
2670 setoption(int argc, char *argv[])
2675 if (argc == 0 || (argc != 1 && argc != 3)) {
2676 UPRINTF("usage: %s [option value]\n", argv[0]);
2680 #define OPTIONINDENT ((int) sizeof("http_proxy"))
2682 for (o = optiontab; o->name != NULL; o++) {
2683 fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT,
2684 o->name, o->value ? o->value : "");
2687 set_option(argv[1], argv[2], 1);
2693 set_option(const char * option, const char * value, int doverbose)
2697 o = getoption(option);
2699 fprintf(ttyout, "No such option `%s'.\n", option);
2703 o->value = ftp_strdup(value);
2704 if (verbose && doverbose)
2705 fprintf(ttyout, "Setting `%s' to `%s'.\n",
2713 unsetoption(int argc, char *argv[])
2718 if (argc == 0 || argc != 2) {
2719 UPRINTF("usage: %s option\n", argv[0]);
2723 o = getoption(argv[1]);
2725 fprintf(ttyout, "No such option `%s'.\n", argv[1]);
2729 fprintf(ttyout, "Unsetting `%s'.\n", o->name);
2734 * Display features supported by the remote host.
2737 feat(int argc, char *argv[])
2739 int oldverbose = verbose;
2742 UPRINTF("usage: %s\n", argv[0]);
2746 if (! features[FEAT_FEAT]) {
2748 "FEAT is not supported by the remote server.\n");
2751 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2752 (void)command("FEAT");
2753 verbose = oldverbose;
2757 mlst(int argc, char *argv[])
2759 int oldverbose = verbose;
2761 if (argc < 1 || argc > 2) {
2762 UPRINTF("usage: %s [remote-path]\n", argv[0]);
2766 if (! features[FEAT_MLST]) {
2768 "MLST is not supported by the remote server.\n");
2771 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2772 COMMAND_1ARG(argc, argv, "MLST");
2773 verbose = oldverbose;
2777 opts(int argc, char *argv[])
2779 int oldverbose = verbose;
2781 if (argc < 2 || argc > 3) {
2782 UPRINTF("usage: %s command [options]\n", argv[0]);
2786 if (! features[FEAT_FEAT]) {
2788 "OPTS is not supported by the remote server.\n");
2791 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2793 command("OPTS %s", argv[1]);
2795 command("OPTS %s %s", argv[1], argv[2]);
2796 verbose = oldverbose;