1 /* $NetBSD: cmds.c,v 1.132 2011/09/16 15:39:26 joerg Exp $ */
4 * Copyright (c) 1996-2009 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.132 2011/09/16 15:39:26 joerg 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>
129 static struct types {
135 { "ascii", "A", TYPE_A, 0 },
136 { "binary", "I", TYPE_I, 0 },
137 { "image", "I", TYPE_I, 0 },
138 { "ebcdic", "E", TYPE_E, 0 },
139 { "tenex", "L", TYPE_L, bytename },
140 { NULL, NULL, 0, NULL }
143 static sigjmp_buf jabort;
145 static int confirm(const char *, const char *);
146 __dead static void mintr(int);
147 static void mabort(const char *);
148 static void set_type(const char *);
150 static const char *doprocess(char *, size_t, const char *, int, int, int);
151 static const char *domap(char *, size_t, const char *);
152 static const char *docase(char *, size_t, const char *);
153 static const char *dotrans(char *, size_t, const char *);
156 * Confirm if "cmd" is to be performed upon "file".
157 * If "file" is NULL, generate a "Continue with" prompt instead.
160 confirm(const char *cmd, const char *file)
162 const char *errormsg;
164 const char *promptleft, *promptright;
166 if (!interactive || confirmrest)
169 promptleft = "Continue with";
176 fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright);
177 (void)fflush(ttyout);
178 if (get_line(stdin, cline, sizeof(cline), &errormsg) < 0) {
180 fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd);
183 switch (tolower((unsigned char)*cline)) {
187 "Prompting off for duration of %s.\n", cmd);
191 fputs("Interactive mode: off.\n", ttyout);
195 fprintf(ttyout, "%s aborted.\n", cmd);
201 " confirmation options:\n"
202 "\ta answer `yes' for the duration of %s\n"
203 "\tn answer `no' for this file\n"
204 "\tp turn off `prompt' mode\n"
205 "\tq stop the current %s\n"
206 "\ty answer `yes' for this file\n"
207 "\t? this help list\n",
209 continue; /* back to while(1) */
220 settype(int argc, char *argv[])
224 if (argc == 0 || argc > 2) {
227 UPRINTF("usage: %s [", argv[0]);
229 for (p = types; p->t_name; p++) {
230 fprintf(ttyout, "%s%s", sep, p->t_name);
233 fputs(" ]\n", ttyout);
238 fprintf(ttyout, "Using %s mode to transfer files.\n", typename);
246 set_type(const char *ttype)
251 for (p = types; p->t_name; p++)
252 if (strcmp(ttype, p->t_name) == 0)
254 if (p->t_name == 0) {
255 fprintf(ttyout, "%s: unknown mode.\n", ttype);
259 if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
260 comret = command("TYPE %s %s", p->t_mode, p->t_arg);
262 comret = command("TYPE %s", p->t_mode);
263 if (comret == COMPLETE) {
264 (void)strlcpy(typename, p->t_name, sizeof(typename));
265 curtype = type = p->t_type;
270 * Internal form of settype; changes current type in use with server
271 * without changing our notion of the type for data transfers.
272 * Used to change to and from ascii for listings.
275 changetype(int newtype, int show)
278 int comret, oldverbose = verbose;
282 if (newtype == curtype)
284 if (ftp_debug == 0 && show == 0)
286 for (p = types; p->t_name; p++)
287 if (newtype == p->t_type)
289 if (p->t_name == 0) {
290 errx(1, "changetype: unknown type %d", newtype);
292 if (newtype == TYPE_L && bytename[0] != '\0')
293 comret = command("TYPE %s %s", p->t_mode, bytename);
295 comret = command("TYPE %s", p->t_mode);
296 if (comret == COMPLETE)
298 verbose = oldverbose;
302 * Set binary transfer type.
306 setbinary(int argc, char *argv[])
310 UPRINTF("usage: %s\n", argv[0]);
318 * Set ascii transfer type.
322 setascii(int argc, char *argv[])
326 UPRINTF("usage: %s\n", argv[0]);
334 * Set tenex transfer type.
338 settenex(int argc, char *argv[])
342 UPRINTF("usage: %s\n", argv[0]);
350 * Set file transfer mode.
354 setftmode(int argc, char *argv[])
358 UPRINTF("usage: %s mode-name\n", argv[0]);
362 fprintf(ttyout, "We only support %s mode, sorry.\n", modename);
367 * Set file transfer format.
371 setform(int argc, char *argv[])
375 UPRINTF("usage: %s format\n", argv[0]);
379 fprintf(ttyout, "We only support %s format, sorry.\n", formname);
384 * Set file transfer structure.
388 setstruct(int argc, char *argv[])
392 UPRINTF("usage: %s struct-mode\n", argv[0]);
396 fprintf(ttyout, "We only support %s structure, sorry.\n", structname);
401 * Send a single file.
404 put(int argc, char *argv[])
406 char buf[MAXPATHLEN];
417 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-file")))
419 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
421 UPRINTF("usage: %s local-file [remote-file]\n", argv[0]);
425 if ((locfile = globulize(argv[1])) == NULL) {
430 if (loc) /* If argv[2] is a copy of the old argv[1], update it */
432 cmd = (argv[0][0] == 'a') ? "APPE" : ((sunique) ? "STOU" : "STOR");
433 remfile = doprocess(buf, sizeof(buf), remfile,
434 0, loc && ntflag, loc && mapflag);
435 sendrequest(cmd, locfile, remfile,
436 locfile != argv[1] || remfile != argv[2]);
441 doprocess(char *dst, size_t dlen, const char *src,
442 int casef, int transf, int mapf)
445 src = docase(dst, dlen, src);
447 src = dotrans(dst, dlen, src);
449 src = domap(dst, dlen, src);
454 * Send multiple files.
457 mput(int argc, char *argv[])
464 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
465 UPRINTF("usage: %s local-files\n", argv[0]);
470 oldintr = xsignal(SIGINT, mintr);
471 if (sigsetjmp(jabort, 1))
476 while ((cp = remglob(argv, 0, NULL)) != NULL) {
477 if (*cp == '\0' || !connected) {
481 if (mflag && confirm(argv[0], cp)) {
482 char buf[MAXPATHLEN];
483 tp = doprocess(buf, sizeof(buf), cp,
484 mcase, ntflag, mapflag);
485 sendrequest((sunique) ? "STOU" : "STOR",
486 cp, tp, cp != tp || !interactive);
487 if (!mflag && fromatty) {
488 ointer = interactive;
490 if (confirm(argv[0], NULL)) {
493 interactive = ointer;
499 for (i = 1; i < argc && connected; i++) {
505 if (mflag && confirm(argv[0], argv[i])) {
506 char buf[MAXPATHLEN];
507 tp = doprocess(buf, sizeof(buf), argv[i],
509 sendrequest((sunique) ? "STOU" : "STOR",
510 argv[i], tp, tp != argv[i] || !interactive);
511 if (!mflag && fromatty) {
512 ointer = interactive;
514 if (confirm(argv[0], NULL)) {
517 interactive = ointer;
523 memset(&gl, 0, sizeof(gl));
524 flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
525 if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
526 warnx("Glob pattern `%s' not found", argv[i]);
530 for (cpp = gl.gl_pathv; cpp && *cpp != NULL && connected;
532 if (mflag && confirm(argv[0], *cpp)) {
533 char buf[MAXPATHLEN];
535 tp = doprocess(buf, sizeof(buf), *cpp,
537 sendrequest((sunique) ? "STOU" : "STOR",
538 *cpp, tp, *cpp != tp || !interactive);
539 if (!mflag && fromatty) {
540 ointer = interactive;
542 if (confirm(argv[0], NULL)) {
545 interactive = ointer;
552 (void)xsignal(SIGINT, oldintr);
557 reget(int argc, char *argv[])
560 (void)getit(argc, argv, 1, "r+");
564 get(int argc, char *argv[])
567 (void)getit(argc, argv, 0, restart_point ? "r+" : "w" );
572 * If restartit is 1, restart the xfer always.
573 * If restartit is -1, restart the xfer only if the remote file is newer.
576 getit(int argc, char *argv[], int restartit, const char *gmode)
579 char *remfile, *olocfile;
581 char buf[MAXPATHLEN];
589 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file")))
591 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
593 UPRINTF("usage: %s remote-file [local-file]\n", argv[0]);
598 if ((olocfile = globulize(argv[2])) == NULL) {
602 locfile = doprocess(buf, sizeof(buf), olocfile,
603 loc && mcase, loc && ntflag, loc && mapflag);
608 if (! features[FEAT_REST_STREAM]) {
610 "Restart is not supported by the remote server.\n");
613 ret = stat(locfile, &stbuf);
614 if (restartit == 1) {
616 warn("Can't stat `%s'", locfile);
619 restart_point = stbuf.st_size;
624 mtime = remotemodtime(argv[1], 0);
627 if (stbuf.st_mtime >= mtime) {
635 recvrequest("RETR", locfile, remfile, gmode,
636 remfile != argv[1] || locfile != argv[2], loc);
639 (void)free(olocfile);
650 write(fileno(ttyout), "\n", 1);
651 siglongjmp(jabort, 1);
655 mabort(const char *cmd)
659 if (mflag && fromatty) {
660 ointer = interactive;
664 if (confirm(cmd, NULL)) {
665 interactive = ointer;
669 interactive = ointer;
676 * Get multiple files.
679 mget(int argc, char *argv[])
685 int volatile restartit;
688 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
689 UPRINTF("usage: %s remote-files\n", argv[0]);
696 if (strcmp(argv[0], "mreget") == 0) {
697 if (! features[FEAT_REST_STREAM]) {
699 "Restart is not supported by the remote server.\n");
704 oldintr = xsignal(SIGINT, mintr);
705 if (sigsetjmp(jabort, 1))
707 while ((cp = remglob(argv, proxy, NULL)) != NULL) {
708 char buf[MAXPATHLEN];
709 if (*cp == '\0' || !connected) {
715 if (! fileindir(cp, localcwd)) {
716 fprintf(ttyout, "Skipping non-relative filename `%s'\n",
720 if (!confirm(argv[0], cp))
722 tp = doprocess(buf, sizeof(buf), cp, mcase, ntflag, mapflag);
726 if (stat(tp, &stbuf) == 0)
727 restart_point = stbuf.st_size;
729 warn("Can't stat `%s'", tp);
731 recvrequest("RETR", tp, cp, restart_point ? "r+" : "w",
732 tp != cp || !interactive, 1);
734 if (!mflag && fromatty) {
735 ointer = interactive;
737 if (confirm(argv[0], NULL))
739 interactive = ointer;
742 (void)xsignal(SIGINT, oldintr);
747 * Read list of filenames from a local file and get those
750 fget(int argc, char *argv[])
754 char buf[MAXPATHLEN], cmdbuf[MAX_C_NAME];
757 UPRINTF("usage: %s localfile\n", argv[0]);
762 fp = fopen(argv[1], "r");
764 fprintf(ttyout, "Can't open source file %s\n", argv[1]);
769 (void)strlcpy(cmdbuf, "get", sizeof(cmdbuf));
771 gmode = restart_point ? "r+" : "w";
773 while (get_line(fp, buf, sizeof(buf), NULL) >= 0) {
777 (void)getit(argc, argv, 0, gmode);
786 return (val ? "on" : "off");
794 status(int argc, char *argv[])
798 UPRINTF("usage: %s\n", argv[0]);
804 fprintf(ttyout, "Connected %sto %s.\n",
805 connected == -1 ? "and logged in" : "", hostname);
807 fputs("Not connected.\n", ttyout);
811 fprintf(ttyout, "Connected for proxy commands to %s.\n",
815 fputs("No proxy connection.\n", ttyout);
819 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode),
820 *gateserver ? gateserver : "(none)", gateport);
821 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
822 onoff(passivemode), onoff(activefallback));
823 fprintf(ttyout, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
824 modename, typename, formname, structname);
825 fprintf(ttyout, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
826 onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob));
827 fprintf(ttyout, "Store unique: %s; Receive unique: %s.\n",
828 onoff(sunique), onoff(runique));
829 fprintf(ttyout, "Preserve modification times: %s.\n", onoff(preserve));
830 fprintf(ttyout, "Case: %s; CR stripping: %s.\n", onoff(mcase),
833 fprintf(ttyout, "Ntrans: (in) %s (out) %s\n", ntin, ntout);
836 fputs("Ntrans: off.\n", ttyout);
839 fprintf(ttyout, "Nmap: (in) %s (out) %s\n", mapin, mapout);
842 fputs("Nmap: off.\n", ttyout);
845 "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
846 onoff(hash), mark, onoff(progress));
848 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
849 onoff(rate_get), rate_get, rate_get_incr);
851 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
852 onoff(rate_put), rate_put, rate_put_incr);
854 "Socket buffer sizes: send %d, receive %d.\n",
855 sndbuf_size, rcvbuf_size);
856 fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
857 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
858 epsv4bad ? " (disabled for this connection)" : "");
859 fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv6: %s%s.\n", onoff(epsv6),
860 epsv6bad ? " (disabled for this connection)" : "");
861 fprintf(ttyout, "Command line editing: %s.\n",
862 #ifdef NO_EDITCOMPLETE
863 "support not compiled in"
864 #else /* !def NO_EDITCOMPLETE */
866 #endif /* !def NO_EDITCOMPLETE */
871 fputs("Macros:\n", ttyout);
872 for (i=0; i<macnum; i++) {
873 fprintf(ttyout, "\t%s\n", macros[i].mac_name);
876 #endif /* !def NO_STATUS */
877 fprintf(ttyout, "Version: %s %s\n", FTP_PRODUCT, FTP_VERSION);
885 togglevar(int argc, char *argv[], int *var, const char *mesg)
889 } else if (argc == 2 && strcasecmp(argv[1], "on") == 0) {
891 } else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
894 UPRINTF("usage: %s [ on | off ]\n", argv[0]);
898 fprintf(ttyout, "%s %s.\n", mesg, onoff(*var));
903 * Set beep on cmd completed mode.
907 setbell(int argc, char *argv[])
910 code = togglevar(argc, argv, &bell, "Bell mode");
914 * Set command line editing
918 setedit(int argc, char *argv[])
921 #ifdef NO_EDITCOMPLETE
923 UPRINTF("usage: %s\n", argv[0]);
928 fputs("Editing support not compiled in; ignoring command.\n",
930 #else /* !def NO_EDITCOMPLETE */
931 code = togglevar(argc, argv, &editing, "Editing mode");
933 #endif /* !def NO_EDITCOMPLETE */
937 * Turn on packet tracing.
941 settrace(int argc, char *argv[])
944 code = togglevar(argc, argv, &trace, "Packet tracing");
948 * Toggle hash mark printing during transfers, or set hash mark bytecount.
952 sethash(int argc, char *argv[])
956 else if (argc != 2) {
957 UPRINTF("usage: %s [ on | off | bytecount ]\n",
961 } else if (strcasecmp(argv[1], "on") == 0)
963 else if (strcasecmp(argv[1], "off") == 0)
968 nmark = strsuftoi(argv[1]);
970 fprintf(ttyout, "mark: bad bytecount value `%s'.\n",
978 fprintf(ttyout, "Hash mark printing %s", onoff(hash));
980 fprintf(ttyout, " (%d bytes/hash mark)", mark);
981 fputs(".\n", ttyout);
988 * Turn on printing of server echo's.
992 setverbose(int argc, char *argv[])
995 code = togglevar(argc, argv, &verbose, "Verbose mode");
999 * Toggle PORT/LPRT cmd use before each data connection.
1003 setport(int argc, char *argv[])
1006 code = togglevar(argc, argv, &sendport, "Use of PORT/LPRT cmds");
1010 * Toggle transfer progress bar.
1014 setprogress(int argc, char *argv[])
1017 code = togglevar(argc, argv, &progress, "Progress bar");
1023 * Turn on interactive prompting during mget, mput, and mdelete.
1027 setprompt(int argc, char *argv[])
1030 code = togglevar(argc, argv, &interactive, "Interactive mode");
1034 * Toggle gate-ftp mode, or set gate-ftp server
1038 setgate(int argc, char *argv[])
1040 static char gsbuf[MAXHOSTNAMELEN];
1042 if (argc == 0 || argc > 3) {
1044 "usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
1047 } else if (argc < 2) {
1048 gatemode = !gatemode;
1050 if (argc == 2 && strcasecmp(argv[1], "on") == 0)
1052 else if (argc == 2 && strcasecmp(argv[1], "off") == 0)
1056 gateport = ftp_strdup(argv[2]);
1057 (void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
1062 if (gatemode && (gateserver == NULL || *gateserver == '\0')) {
1064 "Disabling gate-ftp mode - no gate-ftp server defined.\n");
1067 fprintf(ttyout, "Gate ftp: %s, server %s, port %s.\n",
1068 onoff(gatemode), *gateserver ? gateserver : "(none)",
1075 * Toggle metacharacter interpretation on local file names.
1079 setglob(int argc, char *argv[])
1082 code = togglevar(argc, argv, &doglob, "Globbing");
1086 * Toggle preserving modification times on retrieved files.
1090 setpreserve(int argc, char *argv[])
1093 code = togglevar(argc, argv, &preserve, "Preserve modification times");
1097 * Set debugging mode on/off and/or set level of debugging.
1101 setdebug(int argc, char *argv[])
1103 if (argc == 0 || argc > 2) {
1104 UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
1107 } else if (argc == 2) {
1108 if (strcasecmp(argv[1], "on") == 0)
1110 else if (strcasecmp(argv[1], "off") == 0)
1115 val = strsuftoi(argv[1]);
1117 fprintf(ttyout, "%s: bad debugging value.\n",
1125 ftp_debug = !ftp_debug;
1127 options |= SO_DEBUG;
1129 options &= ~SO_DEBUG;
1130 fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
1131 code = ftp_debug > 0;
1135 * Set current working directory on remote machine.
1138 cd(int argc, char *argv[])
1142 if (argc == 0 || argc > 2 ||
1143 (argc == 1 && !another(&argc, &argv, "remote-directory"))) {
1144 UPRINTF("usage: %s remote-directory\n", argv[0]);
1148 r = command("CWD %s", argv[1]);
1149 if (r == ERROR && code == 500) {
1151 fputs("CWD command not recognized, trying XCWD.\n",
1153 r = command("XCWD %s", argv[1]);
1155 if (r == COMPLETE) {
1162 * Set current working directory on local machine.
1165 lcd(int argc, char *argv[])
1172 argv[1] = localhome;
1175 UPRINTF("usage: %s [local-directory]\n", argv[0]);
1178 if ((locdir = globulize(argv[1])) == NULL)
1180 if (chdir(locdir) == -1)
1181 warn("Can't chdir `%s'", locdir);
1185 fprintf(ttyout, "Local directory now: %s\n", localcwd);
1188 fprintf(ttyout, "Unable to determine local directory\n");
1195 * Delete a single file.
1198 delete(int argc, char *argv[])
1201 if (argc == 0 || argc > 2 ||
1202 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
1203 UPRINTF("usage: %s remote-file\n", argv[0]);
1207 if (command("DELE %s", argv[1]) == COMPLETE)
1212 * Delete multiple files.
1215 mdelete(int argc, char *argv[])
1222 (argc == 1 && !another(&argc, &argv, "remote-files"))) {
1223 UPRINTF("usage: %s [remote-files]\n", argv[0]);
1228 oldintr = xsignal(SIGINT, mintr);
1229 if (sigsetjmp(jabort, 1))
1231 while ((cp = remglob(argv, 0, NULL)) != NULL) {
1236 if (mflag && confirm(argv[0], cp)) {
1237 if (command("DELE %s", cp) == COMPLETE)
1239 if (!mflag && fromatty) {
1240 ointer = interactive;
1242 if (confirm(argv[0], NULL)) {
1245 interactive = ointer;
1249 (void)xsignal(SIGINT, oldintr);
1254 * Rename a remote file.
1257 renamefile(int argc, char *argv[])
1260 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "from-name")))
1262 if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
1264 UPRINTF("usage: %s from-name to-name\n", argv[0]);
1268 if (command("RNFR %s", argv[1]) == CONTINUE &&
1269 command("RNTO %s", argv[2]) == COMPLETE)
1274 * Get a directory listing of remote files.
1275 * Supports being invoked as:
1281 * pdir, pls LIST |$PAGER
1282 * pmlsd MLSD |$PAGER
1285 ls(int argc, char *argv[])
1288 char *remdir, *locbuf;
1289 const char *locfile;
1290 int pagecmd, mlsdcmd;
1295 pagecmd = mlsdcmd = 0;
1297 * the only commands that start with `p' are
1298 * the `pager' versions.
1300 if (argv[0][0] == 'p')
1302 if (strcmp(argv[0] + pagecmd , "mlsd") == 0) {
1303 if (! features[FEAT_MLST]) {
1305 "MLSD is not supported by the remote server.\n");
1315 else if (strcmp(argv[0] + pagecmd, "nlist") == 0)
1324 if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
1326 if (pagecmd || mlsdcmd)
1327 UPRINTF("usage: %s [remote-path]\n", argv[0]);
1329 UPRINTF("usage: %s [remote-path [local-file]]\n",
1339 p = getoptionvalue("pager");
1342 len = strlen(p) + 2;
1343 locbuf = ftp_malloc(len);
1345 (void)strlcpy(locbuf + 1, p, len - 1);
1347 } else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
1348 if ((locbuf = globulize(locfile)) == NULL ||
1349 !confirm("output to local-file:", locbuf)) {
1355 recvrequest(cmd, locfile, remdir, "w", 0, 0);
1362 * Get a directory listing of multiple remote files.
1365 mls(int argc, char *argv[])
1369 int volatile dolist;
1370 char * volatile 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 lmode = (i == 1) ? "w" : "a";
1398 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], lmode,
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];
1425 const char *shellp, *namep;
1429 UPRINTF("usage: %s [command [args]]\n", argv[0]);
1433 oldintr = xsignal(SIGINT, SIG_IGN);
1434 if ((pid = fork()) == 0) {
1435 for (pid = 3; pid < 20; pid++)
1437 (void)xsignal(SIGINT, SIG_DFL);
1438 shellp = getenv("SHELL");
1440 shellp = _PATH_BSHELL;
1441 namep = strrchr(shellp, '/');
1446 (void)strlcpy(shellnam, namep, sizeof(shellnam));
1448 fputs(shellp, ttyout);
1452 execl(shellp, shellnam, "-c", altarg, (char *)0);
1455 execl(shellp, shellnam, (char *)0);
1457 warn("Can't execute `%s'", shellp);
1462 while (wait(&wait_status) != pid)
1464 (void)xsignal(SIGINT, oldintr);
1466 warn("Can't fork a subshell; try again later");
1473 * Send new user information (re-login)
1476 user(int argc, char *argv[])
1479 char emptypass[] = "";
1485 (void)another(&argc, &argv, "username");
1486 if (argc < 2 || argc > 4) {
1488 UPRINTF("usage: %s username [password [account]]\n",
1493 n = command("USER %s", argv[1]);
1494 if (n == CONTINUE) {
1496 password = getpass("Password: ");
1497 if (password == NULL)
1498 password = emptypass;
1502 n = command("PASS %s", password);
1503 memset(password, 0, strlen(password));
1505 if (n == CONTINUE) {
1508 password = getpass("Account: ");
1509 if (password == NULL)
1510 password = emptypass;
1514 n = command("ACCT %s", password);
1515 memset(password, 0, strlen(password));
1517 if (n != COMPLETE) {
1518 fputs("Login failed.\n", ttyout);
1521 if (!aflag && argc == 4) {
1523 (void)command("ACCT %s", password);
1524 memset(password, 0, strlen(password));
1531 * Print working directory on remote machine.
1535 pwd(int argc, char *argv[])
1540 UPRINTF("usage: %s\n", argv[0]);
1546 fprintf(ttyout, "Unable to determine remote directory\n");
1548 fprintf(ttyout, "Remote directory: %s\n", remotecwd);
1554 * Print working directory on local machine.
1557 lpwd(int argc, char *argv[])
1562 UPRINTF("usage: %s\n", argv[0]);
1568 fprintf(ttyout, "Unable to determine local directory\n");
1570 fprintf(ttyout, "Local directory: %s\n", localcwd);
1579 makedir(int argc, char *argv[])
1583 if (argc == 0 || argc > 2 ||
1584 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1585 UPRINTF("usage: %s directory-name\n", argv[0]);
1589 r = command("MKD %s", argv[1]);
1590 if (r == ERROR && code == 500) {
1592 fputs("MKD command not recognized, trying XMKD.\n",
1594 r = command("XMKD %s", argv[1]);
1601 * Remove a directory.
1604 removedir(int argc, char *argv[])
1608 if (argc == 0 || argc > 2 ||
1609 (argc == 1 && !another(&argc, &argv, "directory-name"))) {
1610 UPRINTF("usage: %s directory-name\n", argv[0]);
1614 r = command("RMD %s", argv[1]);
1615 if (r == ERROR && code == 500) {
1617 fputs("RMD command not recognized, trying XRMD.\n",
1619 r = command("XRMD %s", argv[1]);
1626 * Send a line, verbatim, to the remote machine.
1629 quote(int argc, char *argv[])
1633 (argc == 1 && !another(&argc, &argv, "command line to send"))) {
1634 UPRINTF("usage: %s line-to-send\n", argv[0]);
1638 quote1("", argc, argv);
1642 * Send a SITE command to the remote machine. The line
1643 * is sent verbatim to the remote machine, except that the
1644 * word "SITE" is added at the front.
1647 site(int argc, char *argv[])
1651 (argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
1652 UPRINTF("usage: %s line-to-send\n", argv[0]);
1656 quote1("SITE ", argc, argv);
1660 * Turn argv[1..argc) into a space-separated string, then prepend initial text.
1661 * Send the result as a one-line command and get response.
1664 quote1(const char *initial, int argc, char *argv[])
1667 char buf[BUFSIZ]; /* must be >= sizeof(line) */
1669 (void)strlcpy(buf, initial, sizeof(buf));
1670 for (i = 1; i < argc; i++) {
1671 (void)strlcat(buf, argv[i], sizeof(buf));
1673 (void)strlcat(buf, " ", sizeof(buf));
1675 if (command("%s", buf) == PRELIM) {
1676 while (getreply(0) == PRELIM)
1683 do_chmod(int argc, char *argv[])
1686 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "mode")))
1688 if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
1690 UPRINTF("usage: %s mode remote-file\n", argv[0]);
1694 (void)command("SITE CHMOD %s %s", argv[1], argv[2]);
1697 #define COMMAND_1ARG(argc, argv, cmd) \
1701 command(cmd " %s", argv[1])
1704 do_umask(int argc, char *argv[])
1706 int oldverbose = verbose;
1709 UPRINTF("usage: %s [umask]\n", argv[0]);
1714 COMMAND_1ARG(argc, argv, "SITE UMASK");
1715 verbose = oldverbose;
1719 idlecmd(int argc, char *argv[])
1721 int oldverbose = verbose;
1723 if (argc < 1 || argc > 2) {
1724 UPRINTF("usage: %s [seconds]\n", argv[0]);
1729 COMMAND_1ARG(argc, argv, "SITE IDLE");
1730 verbose = oldverbose;
1734 * Ask the other side for help.
1737 rmthelp(int argc, char *argv[])
1739 int oldverbose = verbose;
1742 UPRINTF("usage: %s\n", argv[0]);
1747 COMMAND_1ARG(argc, argv, "HELP");
1748 verbose = oldverbose;
1752 * Terminate session and exit.
1753 * May be called with 0, NULL.
1757 quit(int argc, char *argv[])
1760 /* this may be called with argc == 0, argv == NULL */
1761 if (argc == 0 && argv != NULL) {
1762 UPRINTF("usage: %s\n", argv[0]);
1767 disconnect(0, NULL);
1770 disconnect(0, NULL);
1775 * Terminate session, but don't exit.
1776 * May be called with 0, NULL.
1779 disconnect(int argc, char *argv[])
1782 /* this may be called with argc == 0, argv == NULL */
1783 if (argc == 0 && argv != NULL) {
1784 UPRINTF("usage: %s\n", argv[0]);
1790 (void)command("QUIT");
1795 account(int argc, char *argv[])
1798 char emptypass[] = "";
1800 if (argc == 0 || argc > 2) {
1801 UPRINTF("usage: %s [password]\n", argv[0]);
1808 ap = getpass("Account:");
1812 (void)command("ACCT %s", ap);
1813 memset(ap, 0, strlen(ap));
1816 sigjmp_buf abortprox;
1819 proxabort(int notused)
1834 siglongjmp(abortprox, 1);
1838 doproxy(int argc, char *argv[])
1843 char cmdbuf[MAX_C_NAME];
1845 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
1846 UPRINTF("usage: %s command\n", argv[0]);
1850 c = getcmd(argv[1]);
1851 if (c == (struct cmd *) -1) {
1852 fputs("?Ambiguous command.\n", ttyout);
1857 fputs("?Invalid command.\n", ttyout);
1862 fputs("?Invalid proxy command.\n", ttyout);
1866 if (sigsetjmp(abortprox, 1)) {
1870 oldintr = xsignal(SIGINT, proxabort);
1872 if (c->c_conn && !connected) {
1873 fputs("Not connected.\n", ttyout);
1875 (void)xsignal(SIGINT, oldintr);
1879 cmdpos = strcspn(line, " \t");
1880 if (cmdpos > 0) /* remove leading "proxy " from input buffer */
1881 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
1882 (void)strlcpy(cmdbuf, c->c_name, sizeof(cmdbuf));
1884 (*c->c_handler)(argc-1, argv+1);
1892 (void)xsignal(SIGINT, oldintr);
1896 setcase(int argc, char *argv[])
1899 code = togglevar(argc, argv, &mcase, "Case mapping");
1903 * convert the given name to lower case if it's all upper case, into
1904 * a static buffer which is returned to the caller
1907 docase(char *dst, size_t dlen, const char *src)
1912 for (i = 0; src[i] != '\0' && i < dlen - 1; i++) {
1914 if (islower((unsigned char)dst[i]))
1920 for (i = 0; dst[i] != '\0'; i++)
1921 if (isupper((unsigned char)dst[i]))
1922 dst[i] = tolower((unsigned char)dst[i]);
1928 setcr(int argc, char *argv[])
1931 code = togglevar(argc, argv, &crflag, "Carriage Return stripping");
1935 setntrans(int argc, char *argv[])
1938 if (argc == 0 || argc > 3) {
1939 UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
1945 fputs("Ntrans off.\n", ttyout);
1951 (void)strlcpy(ntin, argv[1], sizeof(ntin));
1956 (void)strlcpy(ntout, argv[2], sizeof(ntout));
1960 dotrans(char *dst, size_t dlen, const char *src)
1966 for (ostop = 0; *(ntout + ostop) && ostop < 16; ostop++)
1968 for (cp1 = src; *cp1; cp1++) {
1970 for (i = 0; *(ntin + i) && i < 16; i++) {
1971 if (*cp1 == *(ntin + i)) {
1974 *cp2++ = *(ntout + i);
1975 if (cp2 - dst >= (ptrdiff_t)(dlen - 1))
1991 setnmap(int argc, char *argv[])
1997 fputs("Nmap off.\n", ttyout);
2002 (argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
2003 UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
2009 cp = strchr(altarg, ' ');
2014 cp = strchr(altarg, ' ');
2017 (void)strlcpy(mapin, altarg, MAXPATHLEN);
2018 while (*++cp == ' ')
2020 (void)strlcpy(mapout, cp, MAXPATHLEN);
2024 domap(char *dst, size_t dlen, const char *src)
2026 const char *cp1 = src;
2028 const char *tp[9], *te[9];
2029 int i, toks[9], toknum = 0, match = 1;
2031 for (i=0; i < 9; ++i) {
2034 while (match && *cp1 && *cp2) {
2037 if (*++cp2 != *cp1) {
2042 if (*(cp2+1) >= '1' && (*cp2+1) <= '9') {
2043 if (*cp1 != *(++cp2+1)) {
2044 toks[toknum = *cp2 - '1']++;
2046 while (*++cp1 && *(cp2+1)
2060 if (match && *cp1) {
2063 if (match && *cp2) {
2067 if (!match && *cp1) /* last token mismatch */
2084 if (*++cp1 == '$' &&
2085 isdigit((unsigned char)*(cp1+1))) {
2086 if (*++cp1 == '0') {
2087 const char *cp3 = src;
2094 else if (toks[toknum = *cp1 - '1']) {
2095 const char *cp3 = tp[toknum];
2097 while (cp3 != te[toknum]) {
2104 while (*cp1 && *cp1 != ',' &&
2109 else if (*cp1 == '$' &&
2110 isdigit((unsigned char)*(cp1+1))) {
2111 if (*++cp1 == '0') {
2112 const char *cp3 = src;
2118 else if (toks[toknum =
2120 const char *cp3=tp[toknum];
2134 "nmap: unbalanced brackets.\n",
2142 while (*++cp1 && *cp1 != ']') {
2143 if (*cp1 == '\\' && *(cp1 + 1)) {
2149 "nmap: unbalanced brackets.\n",
2166 if (isdigit((unsigned char)*(cp1 + 1))) {
2167 if (*++cp1 == '0') {
2168 const char *cp3 = src;
2174 else if (toks[toknum = *cp1 - '1']) {
2175 const char *cp3 = tp[toknum];
2177 while (cp3 != te[toknum]) {
2183 /* intentional drop through */
2191 return *dst ? dst : src;
2195 setpassive(int argc, char *argv[])
2199 passivemode = !passivemode;
2200 activefallback = passivemode;
2201 } else if (argc != 2) {
2203 UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
2206 } else if (strcasecmp(argv[1], "on") == 0) {
2209 } else if (strcasecmp(argv[1], "off") == 0) {
2212 } else if (strcasecmp(argv[1], "auto") == 0) {
2217 fprintf(ttyout, "Passive mode: %s; fallback to active mode: %s.\n",
2218 onoff(passivemode), onoff(activefallback));
2224 setepsv4(int argc, char *argv[])
2226 code = togglevar(argc, argv, &epsv4,
2227 verbose ? "EPSV/EPRT on IPv4" : NULL);
2232 setepsv6(int argc, char *argv[])
2234 code = togglevar(argc, argv, &epsv6,
2235 verbose ? "EPSV/EPRT on IPv6" : NULL);
2240 setepsv(int argc, char*argv[])
2242 setepsv4(argc,argv);
2243 setepsv6(argc,argv);
2247 setsunique(int argc, char *argv[])
2250 code = togglevar(argc, argv, &sunique, "Store unique");
2254 setrunique(int argc, char *argv[])
2257 code = togglevar(argc, argv, &runique, "Receive unique");
2261 parserate(int argc, char *argv[], int cmdlineopt)
2263 int dir, max, incr, showonly;
2264 sigfunc oldusr1, oldusr2;
2266 if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
2270 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
2274 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
2278 dir = max = incr = showonly = 0;
2281 #define RATE_ALL (RATE_GET | RATE_PUT)
2283 if (strcasecmp(argv[1], "all") == 0)
2285 else if (strcasecmp(argv[1], "get") == 0)
2287 else if (strcasecmp(argv[1], "put") == 0)
2293 if ((max = strsuftoi(argv[2])) < 0)
2299 if ((incr = strsuftoi(argv[3])) <= 0)
2304 oldusr1 = xsignal(SIGUSR1, SIG_IGN);
2305 oldusr2 = xsignal(SIGUSR2, SIG_IGN);
2306 if (dir & RATE_GET) {
2309 rate_get_incr = incr;
2311 if (!cmdlineopt || verbose)
2313 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
2314 onoff(rate_get), rate_get, rate_get_incr);
2316 if (dir & RATE_PUT) {
2319 rate_put_incr = incr;
2321 if (!cmdlineopt || verbose)
2323 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
2324 onoff(rate_put), rate_put, rate_put_incr);
2326 (void)xsignal(SIGUSR1, oldusr1);
2327 (void)xsignal(SIGUSR2, oldusr2);
2332 setrate(int argc, char *argv[])
2335 code = parserate(argc, argv, 0);
2338 /* change directory to parent directory */
2340 cdup(int argc, char *argv[])
2345 UPRINTF("usage: %s\n", argv[0]);
2349 r = command("CDUP");
2350 if (r == ERROR && code == 500) {
2352 fputs("CDUP command not recognized, trying XCUP.\n",
2354 r = command("XCUP");
2356 if (r == COMPLETE) {
2363 * Restart transfer at specific point
2366 restart(int argc, char *argv[])
2369 if (argc == 0 || argc > 2) {
2370 UPRINTF("usage: %s [restart-point]\n", argv[0]);
2374 if (! features[FEAT_REST_STREAM]) {
2376 "Restart is not supported by the remote server.\n");
2383 rp = STRTOLL(argv[1], &ep, 10);
2384 if (rp < 0 || *ep != '\0')
2385 fprintf(ttyout, "restart: Invalid offset `%s'\n",
2390 if (restart_point == 0)
2391 fputs("No restart point defined.\n", ttyout);
2394 "Restarting at " LLF " for next get, put or append\n",
2395 (LLT)restart_point);
2399 * Show remote system type
2402 syst(int argc, char *argv[])
2404 int oldverbose = verbose;
2407 UPRINTF("usage: %s\n", argv[0]);
2411 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2412 (void)command("SYST");
2413 verbose = oldverbose;
2417 macdef(int argc, char *argv[])
2425 fputs("Limit of 16 macros have already been defined.\n",
2430 if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
2432 UPRINTF("usage: %s macro_name\n", argv[0]);
2438 "Enter macro line by line, terminating it with a null line.\n",
2440 (void)strlcpy(macros[macnum].mac_name, argv[1],
2441 sizeof(macros[macnum].mac_name));
2443 macros[macnum].mac_start = macbuf;
2445 macros[macnum].mac_start = macros[macnum - 1].mac_end + 1;
2446 tmp = macros[macnum].mac_start;
2447 while (tmp != macbuf+4096) {
2448 if ((c = getchar()) == EOF) {
2449 fputs("macdef: end of file encountered.\n", ttyout);
2453 if ((*tmp = c) == '\n') {
2454 if (tmp == macros[macnum].mac_start) {
2455 macros[macnum++].mac_end = tmp;
2459 if (*(tmp-1) == '\0') {
2460 macros[macnum++].mac_end = tmp - 1;
2469 while ((c = getchar()) != '\n' && c != EOF)
2471 if (c == EOF || getchar() == '\n') {
2472 fputs("Macro not defined - 4K buffer exceeded.\n",
2481 * Get size of file on remote machine
2484 sizecmd(int argc, char *argv[])
2488 if (argc == 0 || argc > 2 ||
2489 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2490 UPRINTF("usage: %s remote-file\n", argv[0]);
2494 size = remotesize(argv[1], 1);
2497 "%s\t" LLF "\n", argv[1], (LLT)size);
2502 * Get last modification time of file on remote machine
2505 modtime(int argc, char *argv[])
2509 if (argc == 0 || argc > 2 ||
2510 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2511 UPRINTF("usage: %s remote-file\n", argv[0]);
2515 mtime = remotemodtime(argv[1], 1);
2517 fprintf(ttyout, "%s\t%s", argv[1],
2518 rfc2822time(localtime(&mtime)));
2523 * Show status on remote machine
2526 rmtstatus(int argc, char *argv[])
2530 UPRINTF("usage: %s [remote-file]\n", argv[0]);
2534 COMMAND_1ARG(argc, argv, "STAT");
2538 * Get file if modtime is more recent than current file
2541 newer(int argc, char *argv[])
2544 if (getit(argc, argv, -1, "w"))
2546 "Local file \"%s\" is newer than remote file \"%s\".\n",
2551 * Display one local file through $PAGER.
2554 lpage(int argc, char *argv[])
2558 char *pager, *locfile;
2560 if (argc == 0 || argc > 2 ||
2561 (argc == 1 && !another(&argc, &argv, "local-file"))) {
2562 UPRINTF("usage: %s local-file\n", argv[0]);
2566 if ((locfile = globulize(argv[1])) == NULL) {
2570 p = getoptionvalue("pager");
2573 len = strlen(p) + strlen(locfile) + 2;
2574 pager = ftp_malloc(len);
2575 (void)strlcpy(pager, p, len);
2576 (void)strlcat(pager, " ", len);
2577 (void)strlcat(pager, locfile, len);
2581 (void)free(locfile);
2585 * Display one remote file through $PAGER.
2588 page(int argc, char *argv[])
2590 int ohash, orestart_point, overbose;
2595 if (argc == 0 || argc > 2 ||
2596 (argc == 1 && !another(&argc, &argv, "remote-file"))) {
2597 UPRINTF("usage: %s remote-file\n", argv[0]);
2601 p = getoptionvalue("pager");
2604 len = strlen(p) + 2;
2605 pager = ftp_malloc(len);
2607 (void)strlcpy(pager + 1, p, len - 1);
2610 orestart_point = restart_point;
2612 hash = restart_point = verbose = 0;
2613 recvrequest("RETR", pager, argv[1], "r+", 1, 0);
2615 restart_point = orestart_point;
2621 * Set the socket send or receive buffer size.
2624 setxferbuf(int argc, char *argv[])
2630 UPRINTF("usage: %s size\n", argv[0]);
2634 if (strcasecmp(argv[0], "sndbuf") == 0)
2636 else if (strcasecmp(argv[0], "rcvbuf") == 0)
2638 else if (strcasecmp(argv[0], "xferbuf") == 0)
2643 if ((size = strsuftoi(argv[1])) == -1)
2647 fprintf(ttyout, "%s: size must be positive.\n", argv[0]);
2655 fprintf(ttyout, "Socket buffer sizes: send %d, receive %d.\n",
2656 sndbuf_size, rcvbuf_size);
2661 * Set or display options (defaults are provided by various env vars)
2664 setoption(int argc, char *argv[])
2669 if (argc == 0 || (argc != 1 && argc != 3)) {
2670 UPRINTF("usage: %s [option value]\n", argv[0]);
2674 #define OPTIONINDENT ((int) sizeof("http_proxy"))
2676 for (o = optiontab; o->name != NULL; o++) {
2677 fprintf(ttyout, "%-*s\t%s\n", OPTIONINDENT,
2678 o->name, o->value ? o->value : "");
2681 set_option(argv[1], argv[2], 1);
2687 set_option(const char * option, const char * value, int doverbose)
2691 o = getoption(option);
2693 fprintf(ttyout, "No such option `%s'.\n", option);
2697 o->value = ftp_strdup(value);
2698 if (verbose && doverbose)
2699 fprintf(ttyout, "Setting `%s' to `%s'.\n",
2707 unsetoption(int argc, char *argv[])
2712 if (argc == 0 || argc != 2) {
2713 UPRINTF("usage: %s option\n", argv[0]);
2717 o = getoption(argv[1]);
2719 fprintf(ttyout, "No such option `%s'.\n", argv[1]);
2723 fprintf(ttyout, "Unsetting `%s'.\n", o->name);
2728 * Display features supported by the remote host.
2731 feat(int argc, char *argv[])
2733 int oldverbose = verbose;
2736 UPRINTF("usage: %s\n", argv[0]);
2740 if (! features[FEAT_FEAT]) {
2742 "FEAT is not supported by the remote server.\n");
2745 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2746 (void)command("FEAT");
2747 verbose = oldverbose;
2751 mlst(int argc, char *argv[])
2753 int oldverbose = verbose;
2755 if (argc < 1 || argc > 2) {
2756 UPRINTF("usage: %s [remote-path]\n", argv[0]);
2760 if (! features[FEAT_MLST]) {
2762 "MLST is not supported by the remote server.\n");
2765 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2766 COMMAND_1ARG(argc, argv, "MLST");
2767 verbose = oldverbose;
2771 opts(int argc, char *argv[])
2773 int oldverbose = verbose;
2775 if (argc < 2 || argc > 3) {
2776 UPRINTF("usage: %s command [options]\n", argv[0]);
2780 if (! features[FEAT_FEAT]) {
2782 "OPTS is not supported by the remote server.\n");
2785 verbose = 1; /* If we aren't verbose, this doesn't do anything! */
2787 command("OPTS %s", argv[1]);
2789 command("OPTS %s %s", argv[1], argv[2]);
2790 verbose = oldverbose;