1 /* $NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $ */
4 * Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
12 * NASA Ames Research Center.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the NetBSD
25 * Foundation, Inc. and its contributors.
26 * 4. Neither the name of The NetBSD Foundation nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
44 * Copyright (c) 1985, 1989, 1993, 1994
45 * The Regents of the University of California. All rights reserved.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * Copyright (C) 1997 and 1998 WIDE Project.
74 * All rights reserved.
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
79 * 1. Redistributions of source code must retain the above copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. Neither the name of the project nor the names of its contributors
85 * may be used to endorse or promote products derived from this software
86 * without specific prior written permission.
88 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
89 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
90 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
91 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
92 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
93 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
94 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
95 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
96 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
97 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 #include <sys/cdefs.h>
104 * 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>
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
},
145 static int confirm(const char *, const char *);
147 static const char *doprocess(char *, size_t, const char *, int, int, int);
148 static const char *domap(char *, size_t, const char *);
149 static const char *docase(char *, size_t, const char *);
150 static const char *dotrans(char *, size_t, const char *);
153 confirm(const char *cmd
, const char *file
)
157 if (!interactive
|| confirmrest
)
160 fprintf(ttyout
, "%s %s [anpqy?]? ", cmd
, file
);
161 (void)fflush(ttyout
);
162 if (fgets(line
, sizeof(line
), stdin
) == NULL
) {
164 fprintf(ttyout
, "\nEOF received; %s aborted\n", mname
);
168 switch (tolower((unsigned char)*line
)) {
172 "Prompting off for duration of %s.\n", cmd
);
176 fputs("Interactive mode: off.\n", ttyout
);
180 fprintf(ttyout
, "%s aborted.\n", mname
);
186 " confirmation options:\n"
187 "\ta answer `yes' for the duration of %s\n"
188 "\tn answer `no' for this file\n"
189 "\tp turn off `prompt' mode\n"
190 "\tq stop the current %s\n"
191 "\ty answer `yes' for this file\n"
192 "\t? this help list\n",
194 continue; /* back to while(1) */
205 settype(int argc
, char *argv
[])
210 if (argc
== 0 || argc
> 2) {
213 fprintf(ttyout
, "usage: %s [", argv
[0]);
215 for (p
= types
; p
->t_name
; p
++) {
216 fprintf(ttyout
, "%s%s", sep
, p
->t_name
);
219 fputs(" ]\n", ttyout
);
224 fprintf(ttyout
, "Using %s mode to transfer files.\n", typename
);
228 for (p
= types
; p
->t_name
; p
++)
229 if (strcmp(argv
[1], p
->t_name
) == 0)
231 if (p
->t_name
== 0) {
232 fprintf(ttyout
, "%s: unknown mode.\n", argv
[1]);
236 if ((p
->t_arg
!= NULL
) && (*(p
->t_arg
) != '\0'))
237 comret
= command("TYPE %s %s", p
->t_mode
, p
->t_arg
);
239 comret
= command("TYPE %s", p
->t_mode
);
240 if (comret
== COMPLETE
) {
241 (void)strlcpy(typename
, p
->t_name
, sizeof(typename
));
242 curtype
= type
= p
->t_type
;
247 * Internal form of settype; changes current type in use with server
248 * without changing our notion of the type for data transfers.
249 * Used to change to and from ascii for listings.
252 changetype(int newtype
, int show
)
255 int comret
, oldverbose
= verbose
;
259 if (newtype
== curtype
)
261 if (debug
== 0 && show
== 0)
263 for (p
= types
; p
->t_name
; p
++)
264 if (newtype
== p
->t_type
)
266 if (p
->t_name
== 0) {
267 warnx("internal error: unknown type %d.", newtype
);
270 if (newtype
== TYPE_L
&& bytename
[0] != '\0')
271 comret
= command("TYPE %s %s", p
->t_mode
, bytename
);
273 comret
= command("TYPE %s", p
->t_mode
);
274 if (comret
== COMPLETE
)
276 verbose
= oldverbose
;
286 * Set binary transfer type.
290 setbinary(int argc
, char *argv
[])
294 fprintf(ttyout
, "usage: %s\n", argv
[0]);
303 * Set ascii transfer type.
307 setascii(int argc
, char *argv
[])
311 fprintf(ttyout
, "usage: %s\n", argv
[0]);
320 * Set tenex transfer type.
324 settenex(int argc
, char *argv
[])
328 fprintf(ttyout
, "usage: %s\n", argv
[0]);
337 * Set file transfer mode.
341 setftmode(int argc
, char *argv
[])
345 fprintf(ttyout
, "usage: %s mode-name\n", argv
[0]);
349 fprintf(ttyout
, "We only support %s mode, sorry.\n", modename
);
354 * Set file transfer format.
358 setform(int argc
, char *argv
[])
362 fprintf(ttyout
, "usage: %s format\n", argv
[0]);
366 fprintf(ttyout
, "We only support %s format, sorry.\n", formname
);
371 * Set file transfer structure.
375 setstruct(int argc
, char *argv
[])
379 fprintf(ttyout
, "usage: %s struct-mode\n", argv
[0]);
383 fprintf(ttyout
, "We only support %s structure, sorry.\n", structname
);
388 * Send a single file.
391 put(int argc
, char *argv
[])
393 char buf
[MAXPATHLEN
];
404 if (argc
== 0 || (argc
== 1 && !another(&argc
, &argv
, "local-file")))
406 if ((argc
< 3 && !another(&argc
, &argv
, "remote-file")) || argc
> 3) {
408 fprintf(ttyout
, "usage: %s local-file [remote-file]\n",
413 if ((locfile
= globulize(argv
[1])) == NULL
) {
418 if (loc
) /* If argv[2] is a copy of the old argv[1], update it */
420 cmd
= (argv
[0][0] == 'a') ? "APPE" : ((sunique
) ? "STOU" : "STOR");
421 remfile
= doprocess(buf
, sizeof(buf
), remfile
,
422 0, loc
&& ntflag
, loc
&& mapflag
);
423 sendrequest(cmd
, locfile
, remfile
,
424 locfile
!= argv
[1] || remfile
!= argv
[2]);
429 doprocess(char *dst
, size_t dlen
, const char *src
,
430 int casef
, int transf
, int mapf
)
433 src
= docase(dst
, dlen
, src
);
435 src
= dotrans(dst
, dlen
, src
);
437 src
= domap(dst
, dlen
, src
);
442 * Send multiple files.
445 mput(int argc
, char *argv
[])
452 if (argc
== 0 || (argc
== 1 && !another(&argc
, &argv
, "local-files"))) {
453 fprintf(ttyout
, "usage: %s local-files\n", argv
[0]);
459 oldintr
= xsignal(SIGINT
, mintr
);
460 if (sigsetjmp(jabort
, 1))
465 while ((cp
= remglob(argv
, 0, NULL
)) != NULL
) {
466 if (*cp
== '\0' || !connected
) {
470 if (mflag
&& confirm(argv
[0], cp
)) {
471 char buf
[MAXPATHLEN
];
472 tp
= doprocess(buf
, sizeof(buf
), cp
,
473 mcase
, ntflag
, mapflag
);
474 sendrequest((sunique
) ? "STOU" : "STOR",
475 cp
, tp
, cp
!= tp
|| !interactive
);
476 if (!mflag
&& fromatty
) {
477 ointer
= interactive
;
479 if (confirm("Continue with", "mput")) {
482 interactive
= ointer
;
488 for (i
= 1; i
< argc
&& connected
; i
++) {
494 if (mflag
&& confirm(argv
[0], argv
[i
])) {
495 char buf
[MAXPATHLEN
];
496 tp
= doprocess(buf
, sizeof(buf
), argv
[i
],
498 sendrequest((sunique
) ? "STOU" : "STOR",
499 argv
[i
], tp
, tp
!= argv
[i
] || !interactive
);
500 if (!mflag
&& fromatty
) {
501 ointer
= interactive
;
503 if (confirm("Continue with", "mput")) {
506 interactive
= ointer
;
512 memset(&gl
, 0, sizeof(gl
));
513 flags
= GLOB_BRACE
|GLOB_NOCHECK
|GLOB_TILDE
;
514 if (glob(argv
[i
], flags
, NULL
, &gl
) || gl
.gl_pathc
== 0) {
515 warnx("%s: not found", argv
[i
]);
519 for (cpp
= gl
.gl_pathv
; cpp
&& *cpp
!= NULL
&& connected
;
521 if (mflag
&& confirm(argv
[0], *cpp
)) {
522 char buf
[MAXPATHLEN
];
524 tp
= doprocess(buf
, sizeof(buf
), *cpp
,
526 sendrequest((sunique
) ? "STOU" : "STOR",
527 *cpp
, tp
, *cpp
!= tp
|| !interactive
);
528 if (!mflag
&& fromatty
) {
529 ointer
= interactive
;
531 if (confirm("Continue with", "mput")) {
534 interactive
= ointer
;
541 (void)xsignal(SIGINT
, oldintr
);
546 reget(int argc
, char *argv
[])
549 (void)getit(argc
, argv
, 1, "r+");
553 get(int argc
, char *argv
[])
556 (void)getit(argc
, argv
, 0, restart_point
? "r+" : "w" );
561 * If restartit is 1, restart the xfer always.
562 * If restartit is -1, restart the xfer only if the remote file is newer.
565 getit(int argc
, char *argv
[], int restartit
, const char *mode
)
568 char *remfile
, *olocfile
;
570 char buf
[MAXPATHLEN
];
578 if (argc
== 0 || (argc
== 1 && !another(&argc
, &argv
, "remote-file")))
580 if ((argc
< 3 && !another(&argc
, &argv
, "local-file")) || argc
> 3) {
582 fprintf(ttyout
, "usage: %s remote-file [local-file]\n",
588 if ((olocfile
= globulize(argv
[2])) == NULL
) {
592 locfile
= doprocess(buf
, sizeof(buf
), olocfile
,
593 loc
&& mcase
, loc
&& ntflag
, loc
&& mapflag
);
598 if (! features
[FEAT_REST_STREAM
]) {
600 "Restart is not supported by the remote server.\n");
603 ret
= stat(locfile
, &stbuf
);
604 if (restartit
== 1) {
606 warn("local: %s", locfile
);
609 restart_point
= stbuf
.st_size
;
614 mtime
= remotemodtime(argv
[1], 0);
617 if (stbuf
.st_mtime
>= mtime
) {
625 recvrequest("RETR", locfile
, remfile
, mode
,
626 remfile
!= argv
[1] || locfile
!= argv
[2], loc
);
629 (void)free(olocfile
);
640 write(fileno(ttyout
), "\n", 1);
641 siglongjmp(jabort
, 1);
649 if (mflag
&& fromatty
) {
650 ointer
= interactive
;
654 if (confirm("Continue with", mname
)) {
655 interactive
= ointer
;
659 interactive
= ointer
;
666 * Get multiple files.
669 mget(int argc
, char *argv
[])
678 (argc
== 1 && !another(&argc
, &argv
, "remote-files"))) {
679 fprintf(ttyout
, "usage: %s remote-files\n", argv
[0]);
687 if (strcmp(argv
[0], "mreget") == 0) {
688 if (! features
[FEAT_REST_STREAM
]) {
690 "Restart is not supported by the remote server.\n");
695 oldintr
= xsignal(SIGINT
, mintr
);
696 if (sigsetjmp(jabort
, 1))
698 while ((cp
= remglob(argv
, proxy
, NULL
)) != NULL
) {
699 char buf
[MAXPATHLEN
];
700 if (*cp
== '\0' || !connected
) {
706 if (! fileindir(cp
, localcwd
)) {
707 fprintf(ttyout
, "Skipping non-relative filename `%s'\n",
711 if (!confirm(argv
[0], cp
))
713 tp
= doprocess(buf
, sizeof(buf
), cp
, mcase
, ntflag
, mapflag
);
717 if (stat(tp
, &stbuf
) == 0)
718 restart_point
= stbuf
.st_size
;
722 recvrequest("RETR", tp
, cp
, restart_point
? "r+" : "w",
723 tp
!= cp
|| !interactive
, 1);
725 if (!mflag
&& fromatty
) {
726 ointer
= interactive
;
728 if (confirm("Continue with", "mget"))
730 interactive
= ointer
;
733 (void)xsignal(SIGINT
, oldintr
);
738 * Read list of filenames from a local file and get those
741 fget(int argc
, char *argv
[])
747 fprintf(ttyout
, "usage: %s localfile\n", argv
[0]);
752 fp
= fopen(argv
[1], "r");
754 fprintf(ttyout
, "Cannot open source file %s\n", argv
[1]);
760 mode
= restart_point
? "r+" : "w";
763 (buf
= fparseln(fp
, NULL
, NULL
, "\0\0\0", 0)) != NULL
;
768 (void)getit(argc
, argv
, 0, mode
);
777 return (value
!= 0 ? "on" : "off");
785 status(int argc
, char *argv
[])
789 fprintf(ttyout
, "usage: %s\n", argv
[0]);
795 fprintf(ttyout
, "Connected %sto %s.\n",
796 connected
== -1 ? "and logged in" : "", hostname
);
798 fputs("Not connected.\n", ttyout
);
802 fprintf(ttyout
, "Connected for proxy commands to %s.\n",
806 fputs("No proxy connection.\n", ttyout
);
810 fprintf(ttyout
, "Gate ftp: %s, server %s, port %s.\n", onoff(gatemode
),
811 *gateserver
? gateserver
: "(none)", gateport
);
812 fprintf(ttyout
, "Passive mode: %s; fallback to active mode: %s.\n",
813 onoff(passivemode
), onoff(activefallback
));
814 fprintf(ttyout
, "Mode: %s; Type: %s; Form: %s; Structure: %s.\n",
815 modename
, typename
, formname
, structname
);
816 fprintf(ttyout
, "Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n",
817 onoff(verbose
), onoff(bell
), onoff(interactive
), onoff(doglob
));
818 fprintf(ttyout
, "Store unique: %s; Receive unique: %s.\n",
819 onoff(sunique
), onoff(runique
));
820 fprintf(ttyout
, "Preserve modification times: %s.\n", onoff(preserve
));
821 fprintf(ttyout
, "Case: %s; CR stripping: %s.\n", onoff(mcase
),
824 fprintf(ttyout
, "Ntrans: (in) %s (out) %s\n", ntin
, ntout
);
827 fputs("Ntrans: off.\n", ttyout
);
830 fprintf(ttyout
, "Nmap: (in) %s (out) %s\n", mapin
, mapout
);
833 fputs("Nmap: off.\n", ttyout
);
836 "Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n",
837 onoff(hash
), mark
, onoff(progress
));
839 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
840 onoff(rate_get
), rate_get
, rate_get_incr
);
842 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
843 onoff(rate_put
), rate_put
, rate_put_incr
);
845 "Socket buffer sizes: send %d, receive %d.\n",
846 sndbuf_size
, rcvbuf_size
);
847 fprintf(ttyout
, "Use of PORT cmds: %s.\n", onoff(sendport
));
848 fprintf(ttyout
, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4
),
849 epsv4bad
? " (disabled for this connection)" : "");
850 fprintf(ttyout
, "Command line editing: %s.\n",
851 #ifdef NO_EDITCOMPLETE
852 "support not compiled in"
853 #else /* !def NO_EDITCOMPLETE */
855 #endif /* !def NO_EDITCOMPLETE */
860 fputs("Macros:\n", ttyout
);
861 for (i
=0; i
<macnum
; i
++) {
862 fprintf(ttyout
, "\t%s\n", macros
[i
].mac_name
);
865 #endif /* !def NO_STATUS */
866 fprintf(ttyout
, "Version: %s %s\n", FTP_PRODUCT
, FTP_VERSION
);
874 togglevar(int argc
, char *argv
[], int *var
, const char *mesg
)
878 } else if (argc
== 2 && strcasecmp(argv
[1], "on") == 0) {
880 } else if (argc
== 2 && strcasecmp(argv
[1], "off") == 0) {
883 fprintf(ttyout
, "usage: %s [ on | off ]\n", argv
[0]);
887 fprintf(ttyout
, "%s %s.\n", mesg
, onoff(*var
));
892 * Set beep on cmd completed mode.
896 setbell(int argc
, char *argv
[])
899 code
= togglevar(argc
, argv
, &bell
, "Bell mode");
903 * Set command line editing
907 setedit(int argc
, char *argv
[])
910 #ifdef NO_EDITCOMPLETE
912 fprintf(ttyout
, "usage: %s\n", argv
[0]);
917 fputs("Editing support not compiled in; ignoring command.\n",
919 #else /* !def NO_EDITCOMPLETE */
920 code
= togglevar(argc
, argv
, &editing
, "Editing mode");
922 #endif /* !def NO_EDITCOMPLETE */
926 * Turn on packet tracing.
930 settrace(int argc
, char *argv
[])
933 code
= togglevar(argc
, argv
, &trace
, "Packet tracing");
937 * Toggle hash mark printing during transfers, or set hash mark bytecount.
941 sethash(int argc
, char *argv
[])
945 else if (argc
!= 2) {
946 fprintf(ttyout
, "usage: %s [ on | off | bytecount ]\n",
950 } else if (strcasecmp(argv
[1], "on") == 0)
952 else if (strcasecmp(argv
[1], "off") == 0)
957 nmark
= strsuftoi(argv
[1]);
959 fprintf(ttyout
, "mark: bad bytecount value `%s'.\n",
967 fprintf(ttyout
, "Hash mark printing %s", onoff(hash
));
969 fprintf(ttyout
, " (%d bytes/hash mark)", mark
);
970 fputs(".\n", ttyout
);
977 * Turn on printing of server echo's.
981 setverbose(int argc
, char *argv
[])
984 code
= togglevar(argc
, argv
, &verbose
, "Verbose mode");
988 * Toggle PORT/LPRT cmd use before each data connection.
992 setport(int argc
, char *argv
[])
995 code
= togglevar(argc
, argv
, &sendport
, "Use of PORT/LPRT cmds");
999 * Toggle transfer progress bar.
1003 setprogress(int argc
, char *argv
[])
1006 code
= togglevar(argc
, argv
, &progress
, "Progress bar");
1012 * Turn on interactive prompting during mget, mput, and mdelete.
1016 setprompt(int argc
, char *argv
[])
1019 code
= togglevar(argc
, argv
, &interactive
, "Interactive mode");
1023 * Toggle gate-ftp mode, or set gate-ftp server
1027 setgate(int argc
, char *argv
[])
1029 static char gsbuf
[MAXHOSTNAMELEN
];
1031 if (argc
== 0 || argc
> 3) {
1033 "usage: %s [ on | off | gateserver [port] ]\n", argv
[0]);
1036 } else if (argc
< 2) {
1037 gatemode
= !gatemode
;
1039 if (argc
== 2 && strcasecmp(argv
[1], "on") == 0)
1041 else if (argc
== 2 && strcasecmp(argv
[1], "off") == 0)
1045 gateport
= xstrdup(argv
[2]);
1046 (void)strlcpy(gsbuf
, argv
[1], sizeof(gsbuf
));
1051 if (gatemode
&& (gateserver
== NULL
|| *gateserver
== '\0')) {
1053 "Disabling gate-ftp mode - no gate-ftp server defined.\n");
1056 fprintf(ttyout
, "Gate ftp: %s, server %s, port %s.\n",
1057 onoff(gatemode
), *gateserver
? gateserver
: "(none)",
1064 * Toggle metacharacter interpretation on local file names.
1068 setglob(int argc
, char *argv
[])
1071 code
= togglevar(argc
, argv
, &doglob
, "Globbing");
1075 * Toggle preserving modification times on retrieved files.
1079 setpreserve(int argc
, char *argv
[])
1082 code
= togglevar(argc
, argv
, &preserve
, "Preserve modification times");
1086 * Set debugging mode on/off and/or set level of debugging.
1090 setdebug(int argc
, char *argv
[])
1092 if (argc
== 0 || argc
> 2) {
1093 fprintf(ttyout
, "usage: %s [ on | off | debuglevel ]\n",
1097 } else if (argc
== 2) {
1098 if (strcasecmp(argv
[1], "on") == 0)
1100 else if (strcasecmp(argv
[1], "off") == 0)
1105 val
= strsuftoi(argv
[1]);
1107 fprintf(ttyout
, "%s: bad debugging value.\n",
1117 options
|= SO_DEBUG
;
1119 options
&= ~SO_DEBUG
;
1120 fprintf(ttyout
, "Debugging %s (debug=%d).\n", onoff(debug
), debug
);
1125 * Set current working directory on remote machine.
1128 cd(int argc
, char *argv
[])
1132 if (argc
== 0 || argc
> 2 ||
1133 (argc
== 1 && !another(&argc
, &argv
, "remote-directory"))) {
1134 fprintf(ttyout
, "usage: %s remote-directory\n", argv
[0]);
1138 r
= command("CWD %s", argv
[1]);
1139 if (r
== ERROR
&& code
== 500) {
1141 fputs("CWD command not recognized, trying XCWD.\n",
1143 r
= command("XCWD %s", argv
[1]);
1145 if (r
== COMPLETE
) {
1152 * Set current working directory on local machine.
1155 lcd(int argc
, char *argv
[])
1162 argv
[1] = localhome
;
1165 fprintf(ttyout
, "usage: %s [local-directory]\n", argv
[0]);
1168 if ((locdir
= globulize(argv
[1])) == NULL
)
1170 if (chdir(locdir
) == -1)
1171 warn("lcd %s", locdir
);
1175 fprintf(ttyout
, "Local directory now: %s\n", localcwd
);
1178 fprintf(ttyout
, "Unable to determine local directory\n");
1185 * Delete a single file.
1188 delete(int argc
, char *argv
[])
1191 if (argc
== 0 || argc
> 2 ||
1192 (argc
== 1 && !another(&argc
, &argv
, "remote-file"))) {
1193 fprintf(ttyout
, "usage: %s remote-file\n", argv
[0]);
1197 if (command("DELE %s", argv
[1]) == COMPLETE
)
1202 * Delete multiple files.
1205 mdelete(int argc
, char *argv
[])
1212 (argc
== 1 && !another(&argc
, &argv
, "remote-files"))) {
1213 fprintf(ttyout
, "usage: %s [remote-files]\n", argv
[0]);
1219 oldintr
= xsignal(SIGINT
, mintr
);
1220 if (sigsetjmp(jabort
, 1))
1222 while ((cp
= remglob(argv
, 0, NULL
)) != NULL
) {
1227 if (mflag
&& confirm(argv
[0], cp
)) {
1228 if (command("DELE %s", cp
) == COMPLETE
)
1230 if (!mflag
&& fromatty
) {
1231 ointer
= interactive
;
1233 if (confirm("Continue with", "mdelete")) {
1236 interactive
= ointer
;
1240 (void)xsignal(SIGINT
, oldintr
);
1245 * Rename a remote file.
1248 renamefile(int argc
, char *argv
[])
1251 if (argc
== 0 || (argc
== 1 && !another(&argc
, &argv
, "from-name")))
1253 if ((argc
< 3 && !another(&argc
, &argv
, "to-name")) || argc
> 3) {
1255 fprintf(ttyout
, "usage: %s from-name to-name\n", argv
[0]);
1259 if (command("RNFR %s", argv
[1]) == CONTINUE
&&
1260 command("RNTO %s", argv
[2]) == COMPLETE
)
1265 * Get a directory listing of remote files.
1266 * Supports being invoked as:
1272 * pdir, pls LIST |$PAGER
1273 * mmlsd MLSD |$PAGER
1276 ls(int argc
, char *argv
[])
1279 char *remdir
, *locfile
;
1280 int freelocfile
, pagecmd
, mlsdcmd
;
1284 freelocfile
= pagecmd
= mlsdcmd
= 0;
1286 * the only commands that start with `p' are
1287 * the `pager' versions.
1289 if (argv
[0][0] == 'p')
1291 if (strcmp(argv
[0] + pagecmd
, "mlsd") == 0) {
1292 if (! features
[FEAT_MLST
]) {
1294 "MLSD is not supported by the remote server.\n");
1304 else if (strcmp(argv
[0] + pagecmd
, "nlist") == 0)
1313 if (argc
> 3 || ((pagecmd
| mlsdcmd
) && argc
> 2)) {
1315 if (pagecmd
|| mlsdcmd
)
1317 "usage: %s [remote-path]\n", argv
[0]);
1320 "usage: %s [remote-path [local-file]]\n",
1330 p
= getoptionvalue("pager");
1333 len
= strlen(p
) + 2;
1334 locfile
= xmalloc(len
);
1336 (void)strlcpy(locfile
+ 1, p
, len
- 1);
1338 } else if ((strcmp(locfile
, "-") != 0) && *locfile
!= '|') {
1340 if ((locfile
= globulize(locfile
)) == NULL
||
1341 !confirm("output to local-file:", locfile
)) {
1347 recvrequest(cmd
, locfile
, remdir
, "w", 0, 0);
1349 if (freelocfile
&& locfile
)
1350 (void)free(locfile
);
1354 * Get a directory listing of multiple remote files.
1357 mls(int argc
, char *argv
[])
1362 char *mode
, *dest
, *odest
;
1366 if (argc
< 2 && !another(&argc
, &argv
, "remote-files"))
1368 if (argc
< 3 && !another(&argc
, &argv
, "local-file")) {
1370 fprintf(ttyout
, "usage: %s remote-files local-file\n", argv
[0]);
1374 odest
= dest
= argv
[argc
- 1];
1375 argv
[argc
- 1] = NULL
;
1377 if (strcmp(dest
, "-") && *dest
!= '|')
1378 if (((dest
= globulize(dest
)) == NULL
) ||
1379 !confirm("output to local-file:", dest
)) {
1383 dolist
= strcmp(argv
[0], "mls");
1385 oldintr
= xsignal(SIGINT
, mintr
);
1386 if (sigsetjmp(jabort
, 1))
1388 for (i
= 1; mflag
&& i
< argc
-1 && connected
; i
++) {
1389 mode
= (i
== 1) ? "w" : "a";
1390 recvrequest(dolist
? "LIST" : "NLST", dest
, argv
[i
], mode
,
1392 if (!mflag
&& fromatty
) {
1393 ointer
= interactive
;
1395 if (confirm("Continue with", argv
[0])) {
1398 interactive
= ointer
;
1401 (void)xsignal(SIGINT
, oldintr
);
1403 if (dest
!= odest
) /* free up after globulize() */
1412 shell(int argc
, char *argv
[])
1416 char shellnam
[MAXPATHLEN
], *shell
, *namep
;
1420 fprintf(ttyout
, "usage: %s [command [args]]\n", argv
[0]);
1424 oldintr
= xsignal(SIGINT
, SIG_IGN
);
1425 if ((pid
= fork()) == 0) {
1426 for (pid
= 3; pid
< 20; pid
++)
1428 (void)xsignal(SIGINT
, SIG_DFL
);
1429 shell
= getenv("SHELL");
1431 shell
= _PATH_BSHELL
;
1432 namep
= strrchr(shell
, '/');
1437 (void)strlcpy(shellnam
, namep
, sizeof(shellnam
));
1439 fputs(shell
, ttyout
);
1443 execl(shell
, shellnam
, "-c", altarg
, (char *)0);
1446 execl(shell
, shellnam
, (char *)0);
1453 while (wait(&wait_status
) != pid
)
1455 (void)xsignal(SIGINT
, oldintr
);
1457 warn("Try again later");
1464 * Send new user information (re-login)
1467 user(int argc
, char *argv
[])
1475 (void)another(&argc
, &argv
, "username");
1476 if (argc
< 2 || argc
> 4) {
1478 fprintf(ttyout
, "usage: %s username [password [account]]\n",
1483 n
= command("USER %s", argv
[1]);
1484 if (n
== CONTINUE
) {
1486 argv
[2] = getpass("Password: ");
1489 n
= command("PASS %s", argv
[2]);
1491 if (n
== CONTINUE
) {
1493 (void)fputs("Account: ", ttyout
);
1494 (void)fflush(ttyout
);
1495 if (fgets(acct
, sizeof(acct
) - 1, stdin
) == NULL
) {
1497 "\nEOF received; login aborted.\n");
1502 acct
[strlen(acct
) - 1] = '\0';
1503 argv
[3] = acct
; argc
++;
1505 n
= command("ACCT %s", argv
[3]);
1508 if (n
!= COMPLETE
) {
1509 fputs("Login failed.\n", ttyout
);
1512 if (!aflag
&& argc
== 4) {
1513 (void)command("ACCT %s", argv
[3]);
1520 * Print working directory on remote machine.
1524 pwd(int argc
, char *argv
[])
1529 fprintf(ttyout
, "usage: %s\n", argv
[0]);
1535 fprintf(ttyout
, "Unable to determine remote directory\n");
1537 fprintf(ttyout
, "Remote directory: %s\n", remotecwd
);
1543 * Print working directory on local machine.
1546 lpwd(int argc
, char *argv
[])
1551 fprintf(ttyout
, "usage: %s\n", argv
[0]);
1557 fprintf(ttyout
, "Unable to determine local directory\n");
1559 fprintf(ttyout
, "Local directory: %s\n", localcwd
);
1568 makedir(int argc
, char *argv
[])
1572 if (argc
== 0 || argc
> 2 ||
1573 (argc
== 1 && !another(&argc
, &argv
, "directory-name"))) {
1574 fprintf(ttyout
, "usage: %s directory-name\n", argv
[0]);
1578 r
= command("MKD %s", argv
[1]);
1579 if (r
== ERROR
&& code
== 500) {
1581 fputs("MKD command not recognized, trying XMKD.\n",
1583 r
= command("XMKD %s", argv
[1]);
1590 * Remove a directory.
1593 removedir(int argc
, char *argv
[])
1597 if (argc
== 0 || argc
> 2 ||
1598 (argc
== 1 && !another(&argc
, &argv
, "directory-name"))) {
1599 fprintf(ttyout
, "usage: %s directory-name\n", argv
[0]);
1603 r
= command("RMD %s", argv
[1]);
1604 if (r
== ERROR
&& code
== 500) {
1606 fputs("RMD command not recognized, trying XRMD.\n",
1608 r
= command("XRMD %s", argv
[1]);
1615 * Send a line, verbatim, to the remote machine.
1618 quote(int argc
, char *argv
[])
1622 (argc
== 1 && !another(&argc
, &argv
, "command line to send"))) {
1623 fprintf(ttyout
, "usage: %s line-to-send\n", argv
[0]);
1627 quote1("", argc
, argv
);
1631 * Send a SITE command to the remote machine. The line
1632 * is sent verbatim to the remote machine, except that the
1633 * word "SITE" is added at the front.
1636 site(int argc
, char *argv
[])
1640 (argc
== 1 && !another(&argc
, &argv
, "arguments to SITE command"))){
1641 fprintf(ttyout
, "usage: %s line-to-send\n", argv
[0]);
1645 quote1("SITE ", argc
, argv
);
1649 * Turn argv[1..argc) into a space-separated string, then prepend initial text.
1650 * Send the result as a one-line command and get response.
1653 quote1(const char *initial
, int argc
, char *argv
[])
1656 char buf
[BUFSIZ
]; /* must be >= sizeof(line) */
1658 (void)strlcpy(buf
, initial
, sizeof(buf
));
1659 for (i
= 1; i
< argc
; i
++) {
1660 (void)strlcat(buf
, argv
[i
], sizeof(buf
));
1662 (void)strlcat(buf
, " ", sizeof(buf
));
1664 if (command("%s", buf
) == PRELIM
) {
1665 while (getreply(0) == PRELIM
)
1672 do_chmod(int argc
, char *argv
[])
1675 if (argc
== 0 || (argc
== 1 && !another(&argc
, &argv
, "mode")))
1677 if ((argc
< 3 && !another(&argc
, &argv
, "remote-file")) || argc
> 3) {
1679 fprintf(ttyout
, "usage: %s mode remote-file\n", argv
[0]);
1683 (void)command("SITE CHMOD %s %s", argv
[1], argv
[2]);
1686 #define COMMAND_1ARG(argc, argv, cmd) \
1690 command(cmd " %s", argv[1])
1693 do_umask(int argc
, char *argv
[])
1695 int oldverbose
= verbose
;
1698 fprintf(ttyout
, "usage: %s [umask]\n", argv
[0]);
1703 COMMAND_1ARG(argc
, argv
, "SITE UMASK");
1704 verbose
= oldverbose
;
1708 idlecmd(int argc
, char *argv
[])
1710 int oldverbose
= verbose
;
1712 if (argc
< 1 || argc
> 2) {
1713 fprintf(ttyout
, "usage: %s [seconds]\n", argv
[0]);
1718 COMMAND_1ARG(argc
, argv
, "SITE IDLE");
1719 verbose
= oldverbose
;
1723 * Ask the other side for help.
1726 rmthelp(int argc
, char *argv
[])
1728 int oldverbose
= verbose
;
1731 fprintf(ttyout
, "usage: %s\n", argv
[0]);
1736 COMMAND_1ARG(argc
, argv
, "HELP");
1737 verbose
= oldverbose
;
1741 * Terminate session and exit.
1742 * May be called with 0, NULL.
1746 quit(int argc
, char *argv
[])
1749 /* this may be called with argc == 0, argv == NULL */
1750 if (argc
== 0 && argv
!= NULL
) {
1751 fprintf(ttyout
, "usage: %s\n", argv
[0]);
1756 disconnect(0, NULL
);
1759 disconnect(0, NULL
);
1764 * Terminate session, but don't exit.
1765 * May be called with 0, NULL.
1768 disconnect(int argc
, char *argv
[])
1771 /* this may be called with argc == 0, argv == NULL */
1772 if (argc
== 0 && argv
!= NULL
) {
1773 fprintf(ttyout
, "usage: %s\n", argv
[0]);
1779 (void)command("QUIT");
1784 account(int argc
, char *argv
[])
1788 if (argc
== 0 || argc
> 2) {
1789 fprintf(ttyout
, "usage: %s [password]\n", argv
[0]);
1796 ap
= getpass("Account:");
1797 (void)command("ACCT %s", ap
);
1800 sigjmp_buf abortprox
;
1803 proxabort(int notused
)
1818 siglongjmp(abortprox
, 1);
1822 doproxy(int argc
, char *argv
[])
1828 if (argc
== 0 || (argc
== 1 && !another(&argc
, &argv
, "command"))) {
1829 fprintf(ttyout
, "usage: %s command\n", argv
[0]);
1833 c
= getcmd(argv
[1]);
1834 if (c
== (struct cmd
*) -1) {
1835 fputs("?Ambiguous command.\n", ttyout
);
1840 fputs("?Invalid command.\n", ttyout
);
1845 fputs("?Invalid proxy command.\n", ttyout
);
1849 if (sigsetjmp(abortprox
, 1)) {
1853 oldintr
= xsignal(SIGINT
, proxabort
);
1855 if (c
->c_conn
&& !connected
) {
1856 fputs("Not connected.\n", ttyout
);
1858 (void)xsignal(SIGINT
, oldintr
);
1862 cmdpos
= strcspn(line
, " \t");
1863 if (cmdpos
> 0) /* remove leading "proxy " from input buffer */
1864 memmove(line
, line
+ cmdpos
+ 1, strlen(line
) - cmdpos
+ 1);
1865 argv
[1] = c
->c_name
;
1866 (*c
->c_handler
)(argc
-1, argv
+1);
1874 (void)xsignal(SIGINT
, oldintr
);
1878 setcase(int argc
, char *argv
[])
1881 code
= togglevar(argc
, argv
, &mcase
, "Case mapping");
1885 * convert the given name to lower case if it's all upper case, into
1886 * a static buffer which is returned to the caller
1889 docase(char *dst
, size_t dlen
, const char *src
)
1894 for (i
= 0; src
[i
] != '\0' && i
< dlen
- 1; i
++) {
1896 if (islower((unsigned char)dst
[i
]))
1902 for (i
= 0; dst
[i
] != '\0'; i
++)
1903 if (isupper((unsigned char)dst
[i
]))
1904 dst
[i
] = tolower((unsigned char)dst
[i
]);
1910 setcr(int argc
, char *argv
[])
1913 code
= togglevar(argc
, argv
, &crflag
, "Carriage Return stripping");
1917 setntrans(int argc
, char *argv
[])
1920 if (argc
== 0 || argc
> 3) {
1921 fprintf(ttyout
, "usage: %s [inchars [outchars]]\n", argv
[0]);
1927 fputs("Ntrans off.\n", ttyout
);
1933 (void)strlcpy(ntin
, argv
[1], sizeof(ntin
));
1938 (void)strlcpy(ntout
, argv
[2], sizeof(ntout
));
1942 dotrans(char *dst
, size_t dlen
, const char *src
)
1948 for (ostop
= 0; *(ntout
+ ostop
) && ostop
< 16; ostop
++)
1950 for (cp1
= src
; *cp1
; cp1
++) {
1952 for (i
= 0; *(ntin
+ i
) && i
< 16; i
++) {
1953 if (*cp1
== *(ntin
+ i
)) {
1956 *cp2
++ = *(ntout
+ i
);
1957 if (cp2
- dst
>= dlen
- 1)
1973 setnmap(int argc
, char *argv
[])
1979 fputs("Nmap off.\n", ttyout
);
1984 (argc
< 3 && !another(&argc
, &argv
, "mapout")) || argc
> 3) {
1985 fprintf(ttyout
, "usage: %s [mapin mapout]\n", argv
[0]);
1991 cp
= strchr(altarg
, ' ');
1996 cp
= strchr(altarg
, ' ');
1999 (void)strlcpy(mapin
, altarg
, MAXPATHLEN
);
2000 while (*++cp
== ' ')
2002 (void)strlcpy(mapout
, cp
, MAXPATHLEN
);
2006 domap(char *dst
, size_t dlen
, const char *src
)
2008 const char *cp1
= src
;
2010 const char *tp
[9], *te
[9];
2011 int i
, toks
[9], toknum
= 0, match
= 1;
2013 for (i
=0; i
< 9; ++i
) {
2016 while (match
&& *cp1
&& *cp2
) {
2019 if (*++cp2
!= *cp1
) {
2024 if (*(cp2
+1) >= '1' && (*cp2
+1) <= '9') {
2025 if (*cp1
!= *(++cp2
+1)) {
2026 toks
[toknum
= *cp2
- '1']++;
2028 while (*++cp1
&& *(cp2
+1)
2042 if (match
&& *cp1
) {
2045 if (match
&& *cp2
) {
2049 if (!match
&& *cp1
) /* last token mismatch */
2066 if (*++cp1
== '$' &&
2067 isdigit((unsigned char)*(cp1
+1))) {
2068 if (*++cp1
== '0') {
2069 const char *cp3
= src
;
2076 else if (toks
[toknum
= *cp1
- '1']) {
2077 const char *cp3
= tp
[toknum
];
2079 while (cp3
!= te
[toknum
]) {
2086 while (*cp1
&& *cp1
!= ',' &&
2091 else if (*cp1
== '$' &&
2092 isdigit((unsigned char)*(cp1
+1))) {
2093 if (*++cp1
== '0') {
2094 const char *cp3
= src
;
2100 else if (toks
[toknum
=
2102 const char *cp3
=tp
[toknum
];
2116 "nmap: unbalanced brackets.\n",
2124 while (*++cp1
&& *cp1
!= ']') {
2125 if (*cp1
== '\\' && *(cp1
+ 1)) {
2131 "nmap: unbalanced brackets.\n",
2148 if (isdigit((unsigned char)*(cp1
+ 1))) {
2149 if (*++cp1
== '0') {
2150 const char *cp3
= src
;
2156 else if (toks
[toknum
= *cp1
- '1']) {
2157 const char *cp3
= tp
[toknum
];
2159 while (cp3
!= te
[toknum
]) {
2165 /* intentional drop through */
2173 return *dst
? dst
: src
;
2177 setpassive(int argc
, char *argv
[])
2181 passivemode
= !passivemode
;
2182 activefallback
= passivemode
;
2183 } else if (argc
!= 2) {
2185 fprintf(ttyout
, "usage: %s [ on | off | auto ]\n", argv
[0]);
2188 } else if (strcasecmp(argv
[1], "on") == 0) {
2191 } else if (strcasecmp(argv
[1], "off") == 0) {
2194 } else if (strcasecmp(argv
[1], "auto") == 0) {
2199 fprintf(ttyout
, "Passive mode: %s; fallback to active mode: %s.\n",
2200 onoff(passivemode
), onoff(activefallback
));
2205 setepsv4(int argc
, char *argv
[])
2208 code
= togglevar(argc
, argv
, &epsv4
,
2209 verbose
? "EPSV/EPRT on IPv4" : NULL
);
2214 setsunique(int argc
, char *argv
[])
2217 code
= togglevar(argc
, argv
, &sunique
, "Store unique");
2221 setrunique(int argc
, char *argv
[])
2224 code
= togglevar(argc
, argv
, &runique
, "Receive unique");
2228 parserate(int argc
, char *argv
[], int cmdlineopt
)
2230 int dir
, max
, incr
, showonly
;
2231 sigfunc oldusr1
, oldusr2
;
2233 if (argc
> 4 || (argc
< (cmdlineopt
? 3 : 2))) {
2237 "usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
2241 "usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
2245 dir
= max
= incr
= showonly
= 0;
2248 #define RATE_ALL (RATE_GET | RATE_PUT)
2250 if (strcasecmp(argv
[1], "all") == 0)
2252 else if (strcasecmp(argv
[1], "get") == 0)
2254 else if (strcasecmp(argv
[1], "put") == 0)
2260 if ((max
= strsuftoi(argv
[2])) < 0)
2266 if ((incr
= strsuftoi(argv
[3])) <= 0)
2271 oldusr1
= xsignal(SIGUSR1
, SIG_IGN
);
2272 oldusr2
= xsignal(SIGUSR2
, SIG_IGN
);
2273 if (dir
& RATE_GET
) {
2276 rate_get_incr
= incr
;
2278 if (!cmdlineopt
|| verbose
)
2280 "Get transfer rate throttle: %s; maximum: %d; increment %d.\n",
2281 onoff(rate_get
), rate_get
, rate_get_incr
);
2283 if (dir
& RATE_PUT
) {
2286 rate_put_incr
= incr
;
2288 if (!cmdlineopt
|| verbose
)
2290 "Put transfer rate throttle: %s; maximum: %d; increment %d.\n",
2291 onoff(rate_put
), rate_put
, rate_put_incr
);
2293 (void)xsignal(SIGUSR1
, oldusr1
);
2294 (void)xsignal(SIGUSR2
, oldusr2
);
2299 setrate(int argc
, char *argv
[])
2302 code
= parserate(argc
, argv
, 0);
2305 /* change directory to parent directory */
2307 cdup(int argc
, char *argv
[])
2312 fprintf(ttyout
, "usage: %s\n", argv
[0]);
2316 r
= command("CDUP");
2317 if (r
== ERROR
&& code
== 500) {
2319 fputs("CDUP command not recognized, trying XCUP.\n",
2321 r
= command("XCUP");
2323 if (r
== COMPLETE
) {
2330 * Restart transfer at specific point
2333 restart(int argc
, char *argv
[])
2336 if (argc
== 0 || argc
> 2) {
2337 fprintf(ttyout
, "usage: %s [restart-point]\n", argv
[0]);
2341 if (! features
[FEAT_REST_STREAM
]) {
2343 "Restart is not supported by the remote server.\n");
2350 rp
= STRTOLL(argv
[1], &ep
, 10);
2351 if (rp
< 0 || *ep
!= '\0')
2352 fprintf(ttyout
, "restart: Invalid offset `%s'\n",
2357 if (restart_point
== 0)
2358 fputs("No restart point defined.\n", ttyout
);
2361 "Restarting at " LLF
" for next get, put or append\n",
2362 (LLT
)restart_point
);
2366 * Show remote system type
2369 syst(int argc
, char *argv
[])
2371 int oldverbose
= verbose
;
2374 fprintf(ttyout
, "usage: %s\n", argv
[0]);
2378 verbose
= 1; /* If we aren't verbose, this doesn't do anything! */
2379 (void)command("SYST");
2380 verbose
= oldverbose
;
2384 macdef(int argc
, char *argv
[])
2392 fputs("Limit of 16 macros have already been defined.\n",
2397 if ((argc
< 2 && !another(&argc
, &argv
, "macro name")) || argc
> 2) {
2399 fprintf(ttyout
, "usage: %s macro_name\n", argv
[0]);
2405 "Enter macro line by line, terminating it with a null line.\n",
2407 (void)strlcpy(macros
[macnum
].mac_name
, argv
[1],
2408 sizeof(macros
[macnum
].mac_name
));
2410 macros
[macnum
].mac_start
= macbuf
;
2412 macros
[macnum
].mac_start
= macros
[macnum
- 1].mac_end
+ 1;
2413 tmp
= macros
[macnum
].mac_start
;
2414 while (tmp
!= macbuf
+4096) {
2415 if ((c
= getchar()) == EOF
) {
2416 fputs("macdef: end of file encountered.\n", ttyout
);
2420 if ((*tmp
= c
) == '\n') {
2421 if (tmp
== macros
[macnum
].mac_start
) {
2422 macros
[macnum
++].mac_end
= tmp
;
2426 if (*(tmp
-1) == '\0') {
2427 macros
[macnum
++].mac_end
= tmp
- 1;
2436 while ((c
= getchar()) != '\n' && c
!= EOF
)
2438 if (c
== EOF
|| getchar() == '\n') {
2439 fputs("Macro not defined - 4K buffer exceeded.\n",
2448 * Get size of file on remote machine
2451 sizecmd(int argc
, char *argv
[])
2455 if (argc
== 0 || argc
> 2 ||
2456 (argc
== 1 && !another(&argc
, &argv
, "remote-file"))) {
2457 fprintf(ttyout
, "usage: %s remote-file\n", argv
[0]);
2461 size
= remotesize(argv
[1], 1);
2464 "%s\t" LLF
"\n", argv
[1], (LLT
)size
);
2469 * Get last modification time of file on remote machine
2472 modtime(int argc
, char *argv
[])
2476 if (argc
== 0 || argc
> 2 ||
2477 (argc
== 1 && !another(&argc
, &argv
, "remote-file"))) {
2478 fprintf(ttyout
, "usage: %s remote-file\n", argv
[0]);
2482 mtime
= remotemodtime(argv
[1], 1);
2484 fprintf(ttyout
, "%s\t%s", argv
[1], asctime(localtime(&mtime
)));
2489 * Show status on remote machine
2492 rmtstatus(int argc
, char *argv
[])
2496 fprintf(ttyout
, "usage: %s [remote-file]\n", argv
[0]);
2500 COMMAND_1ARG(argc
, argv
, "STAT");
2504 * Get file if modtime is more recent than current file
2507 newer(int argc
, char *argv
[])
2510 if (getit(argc
, argv
, -1, "w"))
2512 "Local file \"%s\" is newer than remote file \"%s\".\n",
2517 * Display one local file through $PAGER.
2520 lpage(int argc
, char *argv
[])
2523 char *p
, *pager
, *locfile
;
2525 if (argc
== 0 || argc
> 2 ||
2526 (argc
== 1 && !another(&argc
, &argv
, "local-file"))) {
2527 fprintf(ttyout
, "usage: %s local-file\n", argv
[0]);
2531 if ((locfile
= globulize(argv
[1])) == NULL
) {
2535 p
= getoptionvalue("pager");
2538 len
= strlen(p
) + strlen(locfile
) + 2;
2539 pager
= xmalloc(len
);
2540 (void)strlcpy(pager
, p
, len
);
2541 (void)strlcat(pager
, " ", len
);
2542 (void)strlcat(pager
, locfile
, len
);
2546 (void)free(locfile
);
2550 * Display one remote file through $PAGER.
2553 page(int argc
, char *argv
[])
2555 int ohash
, orestart_point
, overbose
, len
;
2558 if (argc
== 0 || argc
> 2 ||
2559 (argc
== 1 && !another(&argc
, &argv
, "remote-file"))) {
2560 fprintf(ttyout
, "usage: %s remote-file\n", argv
[0]);
2564 p
= getoptionvalue("pager");
2567 len
= strlen(p
) + 2;
2568 pager
= xmalloc(len
);
2570 (void)strlcpy(pager
+ 1, p
, len
- 1);
2573 orestart_point
= restart_point
;
2575 hash
= restart_point
= verbose
= 0;
2576 recvrequest("RETR", pager
, argv
[1], "r+", 1, 0);
2578 restart_point
= orestart_point
;
2584 * Set the socket send or receive buffer size.
2587 setxferbuf(int argc
, char *argv
[])
2593 fprintf(ttyout
, "usage: %s size\n", argv
[0]);
2597 if (strcasecmp(argv
[0], "sndbuf") == 0)
2599 else if (strcasecmp(argv
[0], "rcvbuf") == 0)
2601 else if (strcasecmp(argv
[0], "xferbuf") == 0)
2606 if ((size
= strsuftoi(argv
[1])) == -1)
2610 fprintf(ttyout
, "%s: size must be positive.\n", argv
[0]);
2618 fprintf(ttyout
, "Socket buffer sizes: send %d, receive %d.\n",
2619 sndbuf_size
, rcvbuf_size
);
2624 * Set or display options (defaults are provided by various env vars)
2627 setoption(int argc
, char *argv
[])
2632 if (argc
== 0 || (argc
!= 1 && argc
!= 3)) {
2633 fprintf(ttyout
, "usage: %s [option value]\n", argv
[0]);
2637 #define OPTIONINDENT ((int) sizeof("http_proxy"))
2639 for (o
= optiontab
; o
->name
!= NULL
; o
++) {
2640 fprintf(ttyout
, "%-*s\t%s\n", OPTIONINDENT
,
2641 o
->name
, o
->value
? o
->value
: "");
2644 o
= getoption(argv
[1]);
2646 fprintf(ttyout
, "No such option `%s'.\n", argv
[1]);
2650 o
->value
= xstrdup(argv
[2]);
2652 fprintf(ttyout
, "Setting `%s' to `%s'.\n",
2662 unsetoption(int argc
, char *argv
[])
2667 if (argc
== 0 || argc
!= 2) {
2668 fprintf(ttyout
, "usage: %s option\n", argv
[0]);
2672 o
= getoption(argv
[1]);
2674 fprintf(ttyout
, "No such option `%s'.\n", argv
[1]);
2678 fprintf(ttyout
, "Unsetting `%s'.\n", o
->name
);
2683 * Display features supported by the remote host.
2686 feat(int argc
, char *argv
[])
2688 int oldverbose
= verbose
;
2691 fprintf(ttyout
, "usage: %s\n", argv
[0]);
2695 if (! features
[FEAT_FEAT
]) {
2697 "FEAT is not supported by the remote server.\n");
2700 verbose
= 1; /* If we aren't verbose, this doesn't do anything! */
2701 (void)command("FEAT");
2702 verbose
= oldverbose
;
2706 mlst(int argc
, char *argv
[])
2708 int oldverbose
= verbose
;
2710 if (argc
< 1 || argc
> 2) {
2711 fprintf(ttyout
, "usage: %s [remote-path]\n", argv
[0]);
2715 if (! features
[FEAT_MLST
]) {
2717 "MLST is not supported by the remote server.\n");
2720 verbose
= 1; /* If we aren't verbose, this doesn't do anything! */
2721 COMMAND_1ARG(argc
, argv
, "MLST");
2722 verbose
= oldverbose
;
2726 opts(int argc
, char *argv
[])
2728 int oldverbose
= verbose
;
2730 if (argc
< 2 || argc
> 3) {
2731 fprintf(ttyout
, "usage: %s command [options]\n", argv
[0]);
2735 if (! features
[FEAT_FEAT
]) {
2737 "OPTS is not supported by the remote server.\n");
2740 verbose
= 1; /* If we aren't verbose, this doesn't do anything! */
2742 command("OPTS %s", argv
[1]);
2744 command("OPTS %s %s", argv
[1], argv
[2]);
2745 verbose
= oldverbose
;