* Copyright (c) 1985, 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char copyright
[] =
"@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
* FTP User Program -- Command Interface.
/*#include <sys/ioctl.h>*/
struct passwd
*pw
= NULL
;
char *cp
, homedir
[MAXPATHLEN
];
sp
= getservbyname("ftp", "tcp");
errx(1, "ftp/tcp: unknown service");
while ((ch
= getopt(argc
, argv
, "dgintv")) != EOF
) {
"usage: ftp [-dgintv] [host [port]]\n");
fromatty
= isatty(fileno(stdin
));
cpend
= 0; /* no pending replies */
proxy
= 0; /* proxy not active */
passivemode
= 0; /* passive mode not active */
crflag
= 1; /* strip c.r. on ascii gets */
sendport
= -1; /* not using ports */
* Set up the home directory in case we're globbing.
(void) strcpy(home
, pw
->pw_dir
);
(void) signal(SIGINT
, intr
);
(void) signal(SIGPIPE
, lostpeer
);
top
= setjmp(toplevel
) == 0;
(void) signal(SIGINT
, intr
);
(void) signal(SIGPIPE
, lostpeer
);
(void) shutdown(fileno(cout
), 1+1);
(void) shutdown(data
, 1+1);
(void) shutdown(fileno(cout
), 1+1);
s = strrchr(filename, '/');
if (fgets(line
, sizeof line
, stdin
) == NULL
)
} else if (l
== sizeof(line
) - 2) {
printf("sorry, input line too long\n");
while ((l
= getchar()) != '\n' && l
!= EOF
)
} /* else it was a line without a newline */
if (c
== (struct cmd
*)-1) {
printf("?Ambiguous command\n");
printf("?Invalid command\n");
if (c
->c_conn
&& !connected
) {
printf("Not connected.\n");
(*c
->c_handler
)(margc
, margv
);
if (c
->c_handler
!= help
)
(void) signal(SIGINT
, intr
);
(void) signal(SIGPIPE
, lostpeer
);
for (c
= cmdtab
; p
= c
->c_name
; c
++) {
for (q
= name
; *q
== *p
++; q
++)
if (*q
== 0) /* exact match? */
if (!*q
) { /* the name was a prefix */
if (q
- name
> longest
) {
} else if (q
- name
== longest
)
return ((struct cmd
*)-1);
* Slice a string up into argc/argv.
stringbase
= line
; /* scan from first of buffer */
argbase
= argbuf
; /* store from first of buffer */
while (*argp
++ = slurpstring())
* Parse string into argbuf;
* implemented with FSM to
* handle quoting and strings
char *tmp
= argbase
; /* will return this if token found */
if (*sb
== '!' || *sb
== '$') { /* recognize ! as a token for shell */
switch (slrflag
) { /* and $ as token for macro invoke */
return ((*sb
== '!') ? "!" : "$");
goto OUT
; /* end of token */
sb
++; goto S2
; /* slurp next character */
sb
++; goto S3
; /* slurp quoted string */
*ap
++ = *sb
++; /* add character to token */
argbase
= ap
; /* update storage pointer */
stringbase
= sb
; /* update scan pointer */
#define HELPINDENT ((int) sizeof ("directory"))
* Call each command handler with argc == 0 and argv[0] == name.
int columns
, width
= 0, lines
;
printf("Commands may be abbreviated. Commands are:\n\n");
for (c
= cmdtab
; c
< &cmdtab
[NCMDS
]; c
++) {
int len
= strlen(c
->c_name
);
width
= (width
+ 8) &~ 7;
lines
= (NCMDS
+ columns
- 1) / columns
;
for (i
= 0; i
< lines
; i
++) {
for (j
= 0; j
< columns
; j
++) {
c
= cmdtab
+ j
* lines
+ i
;
if (c
->c_name
&& (!proxy
|| c
->c_proxy
)) {
for (k
=0; k
< strlen(c
->c_name
); k
++) {
if (c
+ lines
>= &cmdtab
[NCMDS
]) {
if (c
== (struct cmd
*)-1)
printf("?Ambiguous help command %s\n", arg
);
else if (c
== (struct cmd
*)0)
printf("?Invalid help command %s\n", arg
);
printf("%-*s\t%s\n", HELPINDENT
,