From 04198da0e3b9bbc0c1e0c7ff781ea96b24043ae5 Mon Sep 17 00:00:00 2001 From: millert Date: Fri, 14 Mar 1997 04:32:12 +0000 Subject: [PATCH] Sync with NetBSD and fix "get foo.txt /dev/tty" wrt progress meter and setting times. --- usr.bin/ftp/cmds.c | 129 ++++++++++++++++++++++++++-------------- usr.bin/ftp/cmdtab.c | 8 ++- usr.bin/ftp/complete.c | 113 +++++++++++++++++++---------------- usr.bin/ftp/domacro.c | 15 +++-- usr.bin/ftp/extern.h | 13 ++-- usr.bin/ftp/fetch.c | 48 ++++++++++++--- usr.bin/ftp/ftp.1 | 54 ++++++++++++++--- usr.bin/ftp/ftp.c | 95 ++++++++++++++++++++++------- usr.bin/ftp/ftp_var.h | 6 +- usr.bin/ftp/main.c | 36 ++++++----- usr.bin/ftp/ruserpass.c | 10 ++-- usr.bin/ftp/util.c | 70 +++++++++++++--------- 12 files changed, 400 insertions(+), 197 deletions(-) diff --git a/usr.bin/ftp/cmds.c b/usr.bin/ftp/cmds.c index bf3ffe662e2..9d5e923797b 100644 --- a/usr.bin/ftp/cmds.c +++ b/usr.bin/ftp/cmds.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmds.c,v 1.15 1997/02/05 04:55:12 millert Exp $ */ -/* $NetBSD: cmds.c,v 1.18 1997/02/01 10:44:54 lukem Exp $ */ +/* $OpenBSD: cmds.c,v 1.16 1997/03/14 04:32:12 millert Exp $ */ +/* $NetBSD: cmds.c,v 1.19 1997/03/13 06:23:11 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: cmds.c,v 1.15 1997/02/05 04:55:12 millert Exp $"; +static char rcsid[] = "$OpenBSD: cmds.c,v 1.16 1997/03/14 04:32:12 millert Exp $"; #endif #endif /* not lint */ @@ -114,7 +114,7 @@ settype(argc, argv) if (strcmp(argv[1], p->t_name) == 0) break; if (p->t_name == 0) { - printf("%s: unknown mode\n", argv[1]); + printf("%s: unknown mode.\n", argv[1]); code = -1; return; } @@ -150,7 +150,7 @@ changetype(newtype, show) if (newtype == p->t_type) break; if (p->t_name == 0) { - printf("ftp: internal error: unknown type %d\n", newtype); + warnx("internal error: unknown type %d.", newtype); return; } if (newtype == TYPE_L && bytename[0] != '\0') @@ -326,7 +326,7 @@ mput(argc, argv) if (proxy) { char *cp, *tp2, tmpbuf[MAXPATHLEN]; - while ((cp = remglob(argv, 0)) != NULL) { + while ((cp = remglob(argv, 0, NULL)) != NULL) { if (*cp == '\0') { mflag = 0; continue; @@ -575,7 +575,7 @@ mget(argc, argv) mflag = 1; oldintr = signal(SIGINT, mabort); (void)setjmp(jabort); - while ((cp = remglob(argv, proxy)) != NULL) { + while ((cp = remglob(argv, proxy, NULL)) != NULL) { if (*cp == '\0') { mflag = 0; continue; @@ -645,32 +645,32 @@ status(argc, argv) pswitch(0); } printf("Passive mode: %s.\n", onoff(passivemode)); - printf("Mode: %s; Type: %s; Form: %s; Structure: %s\n", + printf("Mode: %s; Type: %s; Form: %s; Structure: %s.\n", modename, typename, formname, structname); - printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s\n", + printf("Verbose: %s; Bell: %s; Prompting: %s; Globbing: %s.\n", onoff(verbose), onoff(bell), onoff(interactive), onoff(doglob)); - printf("Store unique: %s; Receive unique: %s\n", onoff(sunique), + printf("Store unique: %s; Receive unique: %s.\n", onoff(sunique), onoff(runique)); - printf("Preserve modification times: %s\n", onoff(preserve)); - printf("Case: %s; CR stripping: %s\n", onoff(mcase), onoff(crflag)); + printf("Preserve modification times: %s.\n", onoff(preserve)); + printf("Case: %s; CR stripping: %s.\n", onoff(mcase), onoff(crflag)); if (ntflag) { printf("Ntrans: (in) %s (out) %s\n", ntin, ntout); } else { - puts("Ntrans: off"); + puts("Ntrans: off."); } if (mapflag) { printf("Nmap: (in) %s (out) %s\n", mapin, mapout); } else { - puts("Nmap: off"); + puts("Nmap: off."); } - printf("Hash mark printing: %s; Mark count: %d; Progress bar: %s\n", + printf("Hash mark printing: %s; Mark count: %d; Progress bar: %s.\n", onoff(hash), mark, onoff(progress)); - printf("Use of PORT cmds: %s\n", onoff(sendport)); + printf("Use of PORT cmds: %s.\n", onoff(sendport)); #ifndef SMALLFTP - printf("Command line editing: %s\n", onoff(editing)); + printf("Command line editing: %s.\n", onoff(editing)); #endif /* !SMALLFTP */ if (macnum > 0) { puts("Macros:"); @@ -699,7 +699,7 @@ togglevar(argc, argv, var, mesg) *var = 0; } else { printf("usage: %s [ on | off ]\n", argv[0]); - return -1; + return (-1); } if (mesg) printf("%s %s.\n", mesg, onoff(*var)); @@ -769,7 +769,7 @@ sethash(argc, argv) else { int nmark = atol(argv[1]); if (nmark < 1) { - printf("%s: bad bytecount value\n", argv[1]); + printf("%s: bad bytecount value.\n", argv[1]); code = -1; return; } @@ -923,7 +923,7 @@ cd(argc, argv) r = command("CWD %s", argv[1]); if (r == ERROR && code == 500) { if (verbose) - puts("CWD command not recognized, trying XCWD"); + puts("CWD command not recognized, trying XCWD."); r = command("XCWD %s", argv[1]); } if (r == COMPLETE) @@ -1002,7 +1002,7 @@ mdelete(argc, argv) mflag = 1; oldintr = signal(SIGINT, mabort); (void)setjmp(jabort); - while ((cp = remglob(argv, 0)) != NULL) { + while ((cp = remglob(argv, 0, NULL)) != NULL) { if (*cp == '\0') { mflag = 0; continue; @@ -1036,7 +1036,7 @@ renamefile(argc, argv) goto usage; if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) { usage: - printf("%s from-name to-name\n", argv[0]); + printf("usage: %s from-name to-name\n", argv[0]); code = -1; return; } @@ -1184,7 +1184,7 @@ shell(argc, argv) (void)signal(SIGINT, old1); (void)signal(SIGQUIT, old2); if (pid == -1) { - warn("%s", "Try again later"); + warn("Try again later"); code = -1; } else { @@ -1252,7 +1252,7 @@ pwd(argc, argv) */ verbose = 1; if (command("PWD") == ERROR && code == 500) { - puts("PWD command not recognized, trying XPWD"); + puts("PWD command not recognized, trying XPWD."); (void)command("XPWD"); } verbose = oldverbose; @@ -1292,7 +1292,7 @@ makedir(argc, argv) } if (command("MKD %s", argv[1]) == ERROR && code == 500) { if (verbose) - puts("MKD command not recognized, trying XMKD"); + puts("MKD command not recognized, trying XMKD."); (void)command("XMKD %s", argv[1]); } } @@ -1314,7 +1314,7 @@ removedir(argc, argv) } if (command("RMD %s", argv[1]) == ERROR && code == 500) { if (verbose) - puts("RMD command not recognized, trying XRMD"); + puts("RMD command not recognized, trying XRMD."); (void)command("XRMD %s", argv[1]); } } @@ -1372,7 +1372,8 @@ quote1(initial, argc, argv) buf[sizeof(buf) - 1] = '\0'; if (argc > 1) { len = strlen(buf); - len += strlen(strncpy(&buf[len], argv[1], sizeof(buf) - len - 1)); + len += strlen(strncpy(&buf[len], argv[1], + sizeof(buf) - len - 1)); for (i = 2; i < argc && len < sizeof(buf); i++) { buf[len++] = ' '; len += strlen(strncpy(&buf[len], argv[i], @@ -1539,19 +1540,19 @@ doproxy(argc, argv) } c = getcmd(argv[1]); if (c == (struct cmd *) -1) { - puts("?Ambiguous command"); + puts("?Ambiguous command."); (void)fflush(stdout); code = -1; return; } if (c == 0) { - puts("?Invalid command"); + puts("?Invalid command."); (void)fflush(stdout); code = -1; return; } if (!c->c_proxy) { - puts("?Invalid proxy command"); + puts("?Invalid proxy command."); (void)fflush(stdout); code = -1; return; @@ -1563,7 +1564,7 @@ doproxy(argc, argv) oldintr = signal(SIGINT, proxabort); pswitch(1); if (c->c_conn && !connected) { - puts("Not connected"); + puts("Not connected."); (void)fflush(stdout); pswitch(0); (void)signal(SIGINT, oldintr); @@ -1668,7 +1669,7 @@ setnmap(argc, argv) return; } if ((argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) { - printf("Usage: %s [mapin mapout]\n", argv[0]); + printf("usage: %s [mapin mapout]\n", argv[0]); code = -1; return; } @@ -1798,7 +1799,8 @@ LOOP: } } if (!*cp2) { - puts("nmap: unbalanced brackets"); + puts( +"nmap: unbalanced brackets."); return (name); } match = 1; @@ -1811,7 +1813,8 @@ LOOP: } } if (!*cp2) { - puts("nmap: unbalanced brackets"); + puts( +"nmap: unbalanced brackets."); return (name); } break; @@ -1897,7 +1900,7 @@ cdup(argc, argv) r = command("CDUP"); if (r == ERROR && code == 500) { if (verbose) - puts("CDUP command not recognized, trying XCUP"); + puts("CDUP command not recognized, trying XCUP."); r = command("XCUP"); } if (r == COMPLETE) @@ -1912,7 +1915,7 @@ restart(argc, argv) { if (argc != 2) - puts("restart: offset not specified"); + puts("restart: offset not specified."); else { restart_point = atol(argv[1]); printf("Restarting at %qd. Execute get, put or append to" @@ -1939,18 +1942,18 @@ macdef(argc, argv) int c; if (macnum == 16) { - puts("Limit of 16 macros have already been defined"); + puts("Limit of 16 macros have already been defined."); code = -1; return; } if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) { - printf("Usage: %s macro_name\n", argv[0]); + printf("usage: %s macro_name\n", argv[0]); code = -1; return; } - if (interactive) { - puts("Enter macro line by line, terminating it with a null line"); - } + if (interactive) + puts( +"Enter macro line by line, terminating it with a null line."); (void)strncpy(macros[macnum].mac_name, argv[1], sizeof(macros[macnum].mac_name) - 1); macros[macnum].mac_name[sizeof(macros[macnum].mac_name) - 1] = '\0'; @@ -1961,7 +1964,7 @@ macdef(argc, argv) tmp = macros[macnum].mac_start; while (tmp != macbuf+4096) { if ((c = getchar()) == EOF) { - puts("macdef: end of file encountered"); + puts("macdef: end of file encountered."); code = -1; return; } @@ -1984,7 +1987,7 @@ macdef(argc, argv) while ((c = getchar()) != '\n' && c != EOF) /* LOOP */; if (c == EOF || getchar() == '\n') { - puts("Macro not defined - 4k buffer exceeded"); + puts("Macro not defined - 4K buffer exceeded."); code = -1; return; } @@ -2055,6 +2058,44 @@ newer(argc, argv) { if (getit(argc, argv, -1, "w")) - printf("Local file \"%s\" is newer than remote file \"%s\"\n", + printf("Local file \"%s\" is newer than remote file \"%s\".\n", argv[2], argv[1]); } + +/* + * Display one file through $PAGER (defaults to "more"). + */ +void +page(argc, argv) + int argc; + char *argv[]; +{ + int orestart_point, ohash, overbose; + char *p, *pager; + + if ((argc < 2 && !another(&argc, &argv, "filename")) || argc > 2) { + printf("usage: %s filename\n", argv[0]); + code = -1; + return; + } + if (!globulize(&argv[1])) { + code = -1; + return; + } + p = getenv("PAGER"); + if (p == NULL) + p = PAGER; + if ((pager = malloc(strlen(p) + 2)) == NULL) + errx(1, "Can't allocate memory for $PAGER"); + (void)sprintf(pager, "|%s", p); + + orestart_point = restart_point; + ohash = hash; + overbose = verbose; + restart_point = hash = verbose = 0; + recvrequest("RETR", pager, argv[1], "r+w", 1); + (void)free(pager); + restart_point = orestart_point; + hash = ohash; + verbose = overbose; +} diff --git a/usr.bin/ftp/cmdtab.c b/usr.bin/ftp/cmdtab.c index 9624ee83556..8c53e9199b2 100644 --- a/usr.bin/ftp/cmdtab.c +++ b/usr.bin/ftp/cmdtab.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmdtab.c,v 1.6 1997/02/03 01:05:34 millert Exp $ */ -/* $NetBSD: cmdtab.c,v 1.12 1997/01/19 14:19:05 lukem Exp $ */ +/* $OpenBSD: cmdtab.c,v 1.7 1997/03/14 04:32:12 millert Exp $ */ +/* $NetBSD: cmdtab.c,v 1.13 1997/03/13 06:23:12 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.6 1997/02/03 01:05:34 millert Exp $"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.7 1997/03/14 04:32:12 millert Exp $"; #endif #endif /* not lint */ @@ -89,6 +89,7 @@ char newerhelp[] = "get file if remote file is newer than local file "; char nlisthelp[] = "nlist contents of remote directory"; char nmaphelp[] = "set templates for default file name mapping"; char ntranshelp[] = "set translation table for default file name mapping"; +char pagehelp[] = "view a remote file through your pager"; char passivehelp[] = "enter passive transfer mode"; char porthelp[] = "toggle use of PORT cmd for each data connection"; char preservehelp[] ="toggle preservation of modification time of " @@ -182,6 +183,7 @@ struct cmd cmdtab[] = { { "nmap", nmaphelp, 0, 0, 1, CMPL0 setnmap }, { "ntrans", ntranshelp, 0, 0, 1, CMPL0 setntrans }, { "open", connecthelp, 0, 0, 1, CMPL0 setpeer }, + { "page", pagehelp, 1, 1, 1, CMPL(r) page }, { "passive", passivehelp, 0, 0, 0, CMPL0 setpassive }, { "preserve", preservehelp, 0, 0, 0, CMPL0 setpreserve }, { "progress", progresshelp, 0, 0, 0, CMPL0 setprogress }, diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c index aee1b1868b1..a80b3125aff 100644 --- a/usr.bin/ftp/complete.c +++ b/usr.bin/ftp/complete.c @@ -1,5 +1,5 @@ -/* $OpenBSD: complete.c,v 1.3 1997/02/05 04:55:14 millert Exp $ */ -/* $NetBSD: complete.c,v 1.2 1997/02/01 10:44:57 lukem Exp $ */ +/* $OpenBSD: complete.c,v 1.4 1997/03/14 04:32:13 millert Exp $ */ +/* $NetBSD: complete.c,v 1.3 1997/03/13 06:23:13 lukem Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: complete.c,v 1.3 1997/02/05 04:55:14 millert Exp $"; +static char rcsid[] = "$OpenBSD: complete.c,v 1.4 1997/03/14 04:32:13 millert Exp $"; #endif /* not lint */ /* @@ -58,7 +58,7 @@ static int comparstr(a, b) const void *a, *b; { - return strcmp(*(char **)a, *(char **)b); + return (strcmp(*(char **)a, *(char **)b)); } /* @@ -83,14 +83,14 @@ complete_ambiguous(word, list, words) wordlen = strlen(word); if (words->sl_cur == 0) - return CC_ERROR; /* no choices available */ + return (CC_ERROR); /* no choices available */ if (words->sl_cur == 1) { /* only once choice available */ strcpy(insertstr, words->sl_str[0]); if (el_insertstr(el, insertstr + wordlen) == -1) - return CC_ERROR; + return (CC_ERROR); else - return CC_REFRESH; + return (CC_REFRESH); } if (!list) { @@ -108,19 +108,19 @@ complete_ambiguous(word, list, words) strncpy(insertstr, lastmatch, matchlen); insertstr[matchlen] = '\0'; if (el_insertstr(el, insertstr + wordlen) == -1) - return CC_ERROR; + return (CC_ERROR); else /* * XXX: really want CC_REFRESH_BEEP */ - return CC_REFRESH; + return (CC_REFRESH); } } putchar('\n'); qsort(words->sl_str, words->sl_cur, sizeof(char *), comparstr); list_vertical(words); - return CC_REDISPLAY; + return (CC_REDISPLAY); } /* @@ -148,7 +148,7 @@ complete_command(word, list) rv = complete_ambiguous(word, list, words); sl_free(words, 0); - return rv; + return (rv); } /* @@ -180,7 +180,7 @@ complete_local(word, list) } if ((dd = opendir(dir)) == NULL) - return CC_ERROR; + return (CC_ERROR); words = sl_init(); @@ -202,7 +202,7 @@ complete_local(word, list) rv = complete_ambiguous(file, list, words); sl_free(words, 1); - return rv; + return (rv); } /* @@ -215,39 +215,50 @@ complete_remote(word, list) { static StringList *dirlist; static char lastdir[MAXPATHLEN]; - static int ftpdslashbug; StringList *words; char dir[MAXPATHLEN]; char *file, *cp; - int i, offset; + int i; unsigned char rv; char *dummyargv[] = { "complete", dir, NULL }; - offset = 0; if ((file = strrchr(word, '/')) == NULL) { - strcpy(dir, "."); + (void)strcpy(dir, "."); file = word; } else { - if (file == word) - strcpy(dir, "/"); - else { - offset = file - word; - strncpy(dir, word, offset); - dir[offset] = '\0'; - offset++; + cp = file; + while (*cp == '/' && cp > word) + cp--; + if (cp == word) { + dir[0] = '/'; + dir[1] = '\0'; + } else { + (void)strncpy(dir, word, cp - word + 1); + dir[cp - word + 1] = '\0'; } file++; } if (dirchange || strcmp(dir, lastdir) != 0) { /* dir not cached */ + char *emesg; + int dirlen, ftpdslashbug; + + dirlen = strlen(dir); + ftpdslashbug = 0; + if (strcmp(dir, "/") == 0) + ftpdslashbug = 1; + else if (strcmp(dir, ".") == 0) + dirlen = 0; + else + dirlen++; if (dirlist != NULL) sl_free(dirlist, 1); dirlist = sl_init(); - ftpdslashbug = 0; mflag = 1; - while ((cp = remglob(dummyargv, 0)) != NULL) { + emesg = NULL; + while ((cp = remglob(dummyargv, 0, &emesg)) != NULL) { char *tcp; if (!mflag) @@ -259,33 +270,35 @@ complete_remote(word, list) /* * Work around ftpd(1) bug, which puts a // instead * of / in front of each filename returned by "NLST /". - * Without this, remote completes of / look ugly. + * Without this, remote completes of / don't work. + * However, only do this if the bug is present. */ - if (dir[0] == '/' && dir[1] == '\0' && - cp[0] == '/' && cp[1] == '/') { - cp++; - ftpdslashbug = 1; - } - tcp = strdup(cp); + if (ftpdslashbug && (cp[dirlen] != '/')) + ftpdslashbug = 0; + tcp = strdup(cp + dirlen + ftpdslashbug); if (tcp == NULL) errx(1, "Can't allocate memory for remote dir"); sl_add(dirlist, tcp); } - strcpy(lastdir, dir); + if (emesg != NULL) { + printf("\n%s\n", emesg); + return (CC_REDISPLAY); + } + (void)strcpy(lastdir, dir); dirchange = 0; } words = sl_init(); for (i = 0; i < dirlist->sl_cur; i++) { cp = dirlist->sl_str[i]; - if (strlen(word) > strlen(cp)) + if (strlen(file) > strlen(cp)) continue; - if (strncmp(word, cp, strlen(word)) == 0) - sl_add(words, cp + offset + ftpdslashbug); + if (strncmp(file, cp, strlen(file)) == 0) + sl_add(words, cp); } rv = complete_ambiguous(file, list, words); sl_free(words, 0); - return rv; + return (rv); } /* @@ -306,7 +319,7 @@ complete(el, ch) lf = el_line(el); len = lf->lastchar - lf->buffer; if (len >= sizeof(line)) - return CC_ERROR; + return (CC_ERROR); strncpy(line, lf->buffer, len); line[len] = '\0'; cursor_pos = line + (lf->cursor - lf->buffer); @@ -315,7 +328,7 @@ complete(el, ch) makeargv(); /* build argc/argv of current line */ if (cursor_argo >= sizeof(word)) - return CC_ERROR; + return (CC_ERROR); dolist = 0; /* if cursor and word is same, list alternatives */ @@ -327,11 +340,11 @@ complete(el, ch) word[cursor_argo] = '\0'; if (cursor_argc == 0) - return complete_command(word, dolist); + return (complete_command(word, dolist)); c = getcmd(margv[0]); if (c == (struct cmd *)-1 || c == 0) - return CC_ERROR; + return (CC_ERROR); celems = strlen(c->c_complete); /* check for 'continuation' completes (which are uppercase) */ @@ -340,26 +353,26 @@ complete(el, ch) cursor_argc = celems; if (cursor_argc > celems) - return CC_ERROR; + return (CC_ERROR); switch (c->c_complete[cursor_argc - 1]) { case 'l': /* local complete */ case 'L': - return complete_local(word, dolist); + return (complete_local(word, dolist)); case 'r': /* remote complete */ case 'R': if (!connected) { - puts("\nMust be connected to complete"); - return CC_REDISPLAY; + puts("\nMust be connected to complete."); + return (CC_REDISPLAY); } - return complete_remote(word, dolist); + return (complete_remote(word, dolist)); case 'c': /* command complete */ case 'C': - return complete_command(word, dolist); + return (complete_command(word, dolist)); case 'n': /* no complete */ default: - return CC_ERROR; + return (CC_ERROR); } - return CC_ERROR; + return (CC_ERROR); } diff --git a/usr.bin/ftp/domacro.c b/usr.bin/ftp/domacro.c index 5dbc939f052..dd16c312bc6 100644 --- a/usr.bin/ftp/domacro.c +++ b/usr.bin/ftp/domacro.c @@ -1,5 +1,5 @@ -/* $OpenBSD: domacro.c,v 1.4 1997/02/03 01:05:36 millert Exp $ */ -/* $NetBSD: domacro.c,v 1.8 1997/01/19 14:19:08 lukem Exp $ */ +/* $OpenBSD: domacro.c,v 1.5 1997/03/14 04:32:13 millert Exp $ */ +/* $NetBSD: domacro.c,v 1.9 1997/03/13 06:23:14 lukem Exp $ */ /* * Copyright (c) 1985, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: domacro.c,v 1.4 1997/02/03 01:05:36 millert Exp $"; +static char rcsid[] = "$OpenBSD: domacro.c,v 1.5 1997/03/14 04:32:13 millert Exp $"; #endif #endif /* not lint */ @@ -59,7 +59,7 @@ domacro(argc, argv) struct cmd *c; if (argc < 2 && !another(&argc, &argv, "macro name")) { - printf("Usage: %s macro_name.\n", argv[0]); + printf("usage: %s macro_name\n", argv[0]); code = -1; return; } @@ -121,11 +121,11 @@ TOP: makeargv(); c = getcmd(margv[0]); if (c == (struct cmd *)-1) { - puts("?Ambiguous command"); + puts("?Ambiguous command."); code = -1; } else if (c == 0) { - puts("?Invalid command"); + puts("?Invalid command."); code = -1; } else if (c->c_conn && !connected) { @@ -133,9 +133,8 @@ TOP: code = -1; } else { - if (verbose) { + if (verbose) puts(line); - } (*c->c_handler)(margc, margv); if (bell && c->c_bell) { (void)putchar('\007'); diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index 1ca06b5583b..67f4d958a61 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -1,5 +1,5 @@ -/* $NetBSD: extern.h,v 1.11 1997/02/01 10:44:58 lukem Exp $ */ -/* $OpenBSD: extern.h,v 1.8 1997/02/05 04:55:15 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.9 1997/03/14 04:32:14 millert Exp $ */ +/* $NetBSD: extern.h,v 1.12 1997/03/13 06:23:15 lukem Exp $ */ /*- * Copyright (c) 1994 The Regents of the University of California. @@ -53,7 +53,7 @@ void cdup __P((int, char **)); void changetype __P((int, int)); void cmdabort __P((int)); void cmdscanner __P((int)); -int command __P(()); +int command __P((const char *, ...)); #ifndef SMALLFTP unsigned char complete __P((EditLine *, int)); #endif /* !SMALLFTP */ @@ -87,7 +87,7 @@ void lpwd __P((int, char **)); void ls __P((int, char **)); void mabort __P((int)); void macdef __P((int, char **)); -void makeargv __P(()); +void makeargv __P((void)); void makedir __P((int, char **)); void mdelete __P((int, char **)); void mget __P((int, char **)); @@ -96,6 +96,7 @@ void modtime __P((int, char **)); void mput __P((int, char **)); char *onoff __P((int)); void newer __P((int, char **)); +void page __P((int, char **)); void progressmeter __P((int)); char *prompt __P((void)); void proxabort __P((int)); @@ -112,7 +113,7 @@ void quote1 __P((const char *, int, char **)); void recvrequest __P((const char *, const char *, const char *, const char *, int)); void reget __P((int, char **)); -char *remglob __P((char **, int)); +char *remglob __P((char **, int, char **)); off_t remotesize __P((const char *, int)); time_t remotemodtime __P((const char *, int)); void removedir __P((int, char **)); @@ -153,7 +154,7 @@ void setverbose __P((int, char **)); void shell __P((int, char **)); void site __P((int, char **)); void sizecmd __P((int, char **)); -char *slurpstring __P(()); +char *slurpstring __P((void)); void status __P((int, char **)); void syst __P((int, char **)); int togglevar __P((int, char **, int *, const char *)); diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index 81e1ea46c81..81377527412 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -1,5 +1,5 @@ -/* $OpenBSD: fetch.c,v 1.3 1997/02/05 04:55:16 millert Exp $ */ -/* $NetBSD: fetch.c,v 1.2 1997/02/01 10:45:00 lukem Exp $ */ +/* $OpenBSD: fetch.c,v 1.4 1997/03/14 04:32:14 millert Exp $ */ +/* $NetBSD: fetch.c,v 1.3 1997/03/13 06:23:15 lukem Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: fetch.c,v 1.3 1997/02/05 04:55:16 millert Exp $"; +static char rcsid[] = "$OpenBSD: fetch.c,v 1.4 1997/03/14 04:32:14 millert Exp $"; #endif /* not lint */ /* @@ -202,6 +202,8 @@ http_get(line) for (i = 0, buflen = sizeof(buf), cp = buf; i < buflen; cp++, i++) { if (read(s, cp, 1) != 1) goto improper; + if (*cp == '\r') + continue; if (*cp == '\n') break; } @@ -224,6 +226,8 @@ http_get(line) for (i = 0, buflen = sizeof(buf), cp = buf; i < buflen; cp++, i++) { if (read(s, cp, 1) != 1) goto improper; + if (*cp == '\r') + continue; if (*cp == '\n' && c == '\n') break; c = *cp; @@ -331,7 +335,7 @@ aborthttp(notused) { alarmtimer(0); - puts("\nhttp fetch aborted"); + puts("\nhttp fetch aborted."); (void)fflush(stdout); longjmp(httpabort, 1); } @@ -359,6 +363,8 @@ auto_fetch(argc, argv) char *xargv[5]; char *cp, *line, *host, *dir, *file, *portnum; int rval, xargc, argpos; + int dirhasglob, filehasglob; + char rempath[MAXPATHLEN]; argpos = 0; @@ -476,8 +482,18 @@ auto_fetch(argc, argv) } } + dirhasglob = filehasglob = 0; + if (doglob) { + if (! EMPTYSTRING(dir) && + strpbrk(dir, "*?[]{}") != NULL) + dirhasglob = 1; + if (! EMPTYSTRING(file) && + strpbrk(file, "*?[]{}") != NULL) + filehasglob = 1; + } + /* Change directories, if necessary. */ - if (! EMPTYSTRING(dir)) { + if (! EMPTYSTRING(dir) && !dirhasglob) { xargv[0] = "cd"; xargv[1] = dir; xargv[2] = NULL; @@ -496,13 +512,27 @@ auto_fetch(argc, argv) if (!verbose) printf("Retrieving %s/%s\n", dir ? dir : "", file); - /* Fetch the file. */ + if (dirhasglob) { + snprintf(rempath, sizeof(rempath), "%s/%s", dir, file); + file = rempath; + } + + /* Fetch the file(s). */ xargv[0] = "get"; xargv[1] = file; xargv[2] = NULL; - get(2, xargv); - - if ((code / 100) != COMPLETE) /* XXX: is this valid? */ + if (dirhasglob || filehasglob) { + int ointeractive; + + ointeractive = interactive; + interactive = 0; + xargv[0] = "mget"; + mget(2, xargv); + interactive = 1; + } else + get(2, xargv); + + if ((code / 100) != COMPLETE) rval = argpos + 1; } if (connected && rval != -1) diff --git a/usr.bin/ftp/ftp.1 b/usr.bin/ftp/ftp.1 index 95af2319791..f003760e9a9 100644 --- a/usr.bin/ftp/ftp.1 +++ b/usr.bin/ftp/ftp.1 @@ -1,5 +1,5 @@ -.\" $OpenBSD: ftp.1,v 1.8 1997/02/18 18:04:28 kstailey Exp $ -.\" $NetBSD: ftp.1,v 1.17 1997/02/01 10:45:01 lukem Exp $ +.\" $OpenBSD: ftp.1,v 1.9 1997/03/14 04:32:15 millert Exp $ +.\" $NetBSD: ftp.1,v 1.18 1997/03/13 06:23:16 lukem Exp $ .\" .\" Copyright (c) 1985, 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -34,7 +34,7 @@ .\" .\" @(#)ftp.1 8.3 (Berkeley) 10/9/94 .\" -.Dd January 20, 1997 +.Dd February 23, 1997 .Dt FTP 1 .Os BSD 4.2 .Sh NAME @@ -62,7 +62,7 @@ ftp://\fIhost\fR[:\fIport\fR]/\fIfile\fR[/] .Nm ftp http://\fIhost\fR[:\fIport\fR]/\fIfile\fR .Nm ftp -\fIhost\fR:\fI/path/file\fR[/] +\fIhost\fR:[/\fIpath\fR/]\fIfile\fR[/] .Sh DESCRIPTION .Nm Ftp is the user interface to the @@ -73,7 +73,9 @@ remote network site. .Pp The latter three usage formats will fetch a file using either the HTTP or FTP protocols into the current directory. -This is ideal for scripts. +This is ideal for scripts. Refer to +.Sx AUTO-FETCHING FILES +below for more information. .Pp Options may be specified at the command line, or to the command interpreter. @@ -85,7 +87,7 @@ to bypass normal login procedure, and use an anonymous login instead. .It Fl d Enables debugging. .It Fl e -Suppress the use of editline(3). Useful for Emacs ange-ftp. +Disables command line editing. Useful for Emacs ange-ftp. .It Fl g Disables file name globbing. .It Fl i @@ -635,6 +637,13 @@ will also attempt to automatically log the user in to the .Tn FTP server (see below). +.It Ic page Ar file +Retrieve +.Ic file +and display with the program defined in +.Ev PAGER +(which defaults to +.Xr more 1 ). .It Ic passive Toggle passive mode. If passive mode is turned on (default is off), the ftp client will @@ -660,6 +669,15 @@ command by RFC 1123, some do not.) Toggle preservation of modification times on retrieved files. .It Ic progress Toggle display of transfer progress bar. +The progress bar will be disabled for a transfer that has +.Ar local-file +as +.Sq Fl +or a command that starts with +.Sq \&| . +Refer to +.Sx FILE NAMING CONVENTIONS +for more information. .It Ic prompt Toggle interactive prompting. Interactive prompting @@ -1013,6 +1031,24 @@ mode ready for further input. If successive auto-fetch ftp elements refer to the same host, then the connection is maintained between transfers, reducing overhead on connection creation and deletion. +.Pp +If +.Ic file +contains a glob character and globbing is enabled, +(see +.Ic glob ), +then the equivalent of +.Ic "mget file" +is performed. +.Pp +If the directory component of +.Ic file +contains no globbing characters, +it is stored in the current directory as the +.Xr basename 1 +of +.Ic file . +Otherwise, the remote name is used as the local name. .Sh ABORTING A FILE TRANSFER To abort a file transfer, use the terminal interrupt key (usually Ctrl-C). @@ -1240,7 +1276,7 @@ supports interactive command line editing, via the library. It is enabled with the .Ic edit -command, and is enabled by default. +command, and is enabled by default if input is from a tty. Previous lines can be recalled and edited with the arrow keys, and other GNU Emacs-style editing keys may be used as well. .Pp @@ -1269,6 +1305,10 @@ utilizes the following environment variables. For default location of a .Pa .netrc file, if one exists. +.It Ev PAGER +Used by +.Ic page +to display files. .It Ev SHELL For default shell. .It Ev http_proxy diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c index cb0e8ac8044..d75b6b7396d 100644 --- a/usr.bin/ftp/ftp.c +++ b/usr.bin/ftp/ftp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ftp.c,v 1.12 1997/02/05 04:55:18 millert Exp $ */ -/* $NetBSD: ftp.c,v 1.22 1997/02/01 10:45:03 lukem Exp $ */ +/* $OpenBSD: ftp.c,v 1.13 1997/03/14 04:32:16 millert Exp $ */ +/* $NetBSD: ftp.c,v 1.23 1997/03/13 06:23:17 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94"; #else -static char rcsid[] = "$OpenBSD: ftp.c,v 1.12 1997/02/05 04:55:18 millert Exp $"; +static char rcsid[] = "$OpenBSD: ftp.c,v 1.13 1997/03/14 04:32:16 millert Exp $"; #endif #endif /* not lint */ @@ -63,7 +63,11 @@ static char rcsid[] = "$OpenBSD: ftp.c,v 1.12 1997/02/05 04:55:18 millert Exp $" #include #include #include +#ifdef __STDC__ +#include +#else #include +#endif #include "ftp_var.h" @@ -300,19 +304,29 @@ cmdabort(notused) /*VARARGS*/ int +#ifdef __STDC__ +command(const char *fmt, ...) +#else command(va_alist) -va_dcl + va_dcl +#endif { va_list ap; - char *fmt; int r; sig_t oldintr; +#ifndef __STDC__ + const char *fmt; +#endif abrtflag = 0; if (debug) { fputs("---> ", stdout); +#ifdef __STDC__ + va_start(ap, fmt); +#else va_start(ap); - fmt = va_arg(ap, char *); + fmt = va_arg(ap, const char *); +#endif if (strncmp("PASS ", fmt, 5) == 0) fputs("PASS XXXX", stdout); else if (strncmp("ACCT ", fmt, 5) == 0) @@ -324,13 +338,17 @@ va_dcl (void)fflush(stdout); } if (cout == NULL) { - warn("No control connection for command"); + warnx("No control connection for command."); code = -1; return (0); } oldintr = signal(SIGINT, cmdabort); +#ifdef __STDC__ + va_start(ap, fmt); +#else va_start(ap); fmt = va_arg(ap, char *); +#endif vfprintf(cout, fmt, ap); va_end(ap); fputs("\r\n", cout); @@ -391,7 +409,7 @@ getreply(expecteof) lostpeer(); if (verbose) { puts( -"421 Service not available, remote server has closed connection"); +"421 Service not available, remote server has closed connection."); (void)fflush(stdout); } code = 421; @@ -482,7 +500,7 @@ abortsend(notused) alarmtimer(0); mflag = 0; abrtflag = 0; - puts("\nsend aborted\nwaiting for remote to finish abort"); + puts("\nsend aborted\nwaiting for remote to finish abort."); (void)fflush(stdout); longjmp(sendabort, 1); } @@ -499,11 +517,13 @@ sendrequest(cmd, local, remote, printnames) sig_t oldinti, oldintr, oldintp; off_t hashbytes; char *lmode, buf[BUFSIZ], *bufp; + int oprogress; hashbytes = mark; direction = "sent"; bytes = 0; filesize = -1; + oprogress = progress; if (verbose && printnames) { if (local && *local != '-') printf("local: %s ", local); @@ -535,14 +555,16 @@ sendrequest(cmd, local, remote, printnames) (void)signal(SIGPIPE, oldintp); if (oldinti) (void)signal(SIGINFO, oldinti); + progress = oprogress; code = -1; return; } oldintr = signal(SIGINT, abortsend); oldinti = signal(SIGINFO, psummary); - if (strcmp(local, "-") == 0) + if (strcmp(local, "-") == 0) { fin = stdin; - else if (*local == '|') { + progress = 0; + } else if (*local == '|') { oldintp = signal(SIGPIPE, SIG_IGN); fin = popen(local + 1, "r"); if (fin == NULL) { @@ -553,6 +575,7 @@ sendrequest(cmd, local, remote, printnames) code = -1; return; } + progress = 0; closefunc = pclose; } else { fin = fopen(local, "r"); @@ -581,6 +604,7 @@ sendrequest(cmd, local, remote, printnames) if (oldintp) (void)signal(SIGPIPE, oldintp); code = -1; + progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); return; @@ -605,6 +629,7 @@ sendrequest(cmd, local, remote, printnames) if (rc < 0) { warn("local: %s", local); restart_point = 0; + progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); return; @@ -612,6 +637,7 @@ sendrequest(cmd, local, remote, printnames) if (command("REST %ld", (long) restart_point) != CONTINUE) { restart_point = 0; + progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); return; @@ -623,6 +649,7 @@ sendrequest(cmd, local, remote, printnames) if (command("%s %s", cmd, remote) != PRELIM) { (void)signal(SIGINT, oldintr); (void)signal(SIGINFO, oldinti); + progress = oprogress; if (oldintp) (void)signal(SIGPIPE, oldintp); if (closefunc != NULL) @@ -633,6 +660,7 @@ sendrequest(cmd, local, remote, printnames) if (command("%s", cmd) != PRELIM) { (void)signal(SIGINT, oldintr); (void)signal(SIGINFO, oldinti); + progress = oprogress; if (oldintp) (void)signal(SIGPIPE, oldintp); if (closefunc != NULL) @@ -716,6 +744,7 @@ sendrequest(cmd, local, remote, printnames) break; } progressmeter(1); + progress = oprogress; if (closefunc != NULL) (*closefunc)(fin); (void)fclose(dout); @@ -730,6 +759,7 @@ sendrequest(cmd, local, remote, printnames) abort: (void)signal(SIGINT, oldintr); (void)signal(SIGINFO, oldinti); + progress = oprogress; if (oldintp) (void)signal(SIGPIPE, oldintp); if (!cpend) { @@ -760,7 +790,7 @@ abortrecv(notused) alarmtimer(0); mflag = 0; abrtflag = 0; - puts("\nreceive aborted\nwaiting for remote to finish abort"); + puts("\nreceive aborted\nwaiting for remote to finish abort."); (void)fflush(stdout); longjmp(recvabort, 1); } @@ -779,11 +809,13 @@ recvrequest(cmd, local, remote, lmode, printnames) off_t hashbytes; struct stat st; time_t mtime; + int oprogress; hashbytes = mark; direction = "received"; bytes = 0; filesize = -1; + oprogress = progress; is_retr = strcmp(cmd, "RETR") == 0; if (is_retr && verbose && printnames) { if (local && *local != '-') @@ -897,15 +929,17 @@ recvrequest(cmd, local, remote, lmode, printnames) din = dataconn("r"); if (din == NULL) goto abort; - if (strcmp(local, "-") == 0) + if (strcmp(local, "-") == 0) { fout = stdout; - else if (*local == '|') { + progress = 0; + } else if (*local == '|') { oldintp = signal(SIGPIPE, SIG_IGN); fout = popen(local + 1, "w"); if (fout == NULL) { warn("%s", local+1); goto abort; } + progress = 0; closefunc = pclose; } else { fout = fopen(local, lmode); @@ -928,6 +962,10 @@ recvrequest(cmd, local, remote, lmode, printnames) } bufsize = st.st_blksize; } + if (!(st.st_mode & S_IFREG)) { + progress = 0; + preserve = 0; + } progressmeter(-1); switch (curtype) { @@ -936,6 +974,7 @@ recvrequest(cmd, local, remote, lmode, printnames) if (restart_point && lseek(fileno(fout), restart_point, SEEK_SET) < 0) { warn("local: %s", local); + progress = oprogress; if (closefunc != NULL) (*closefunc)(fout); return; @@ -988,6 +1027,7 @@ recvrequest(cmd, local, remote, lmode, printnames) if (fseek(fout, 0L, SEEK_CUR) < 0) { done: warn("local: %s", local); + progress = oprogress; if (closefunc != NULL) (*closefunc)(fout); return; @@ -1022,8 +1062,8 @@ done: } break2: if (bare_lfs) { - printf("WARNING! %d bare linefeeds received in ASCII mode\n", - bare_lfs); + printf( +"WARNING! %d bare linefeeds received in ASCII mode.\n", bare_lfs); puts("File may not have transferred correctly."); } if (hash && (!progress || filesize < 0)) { @@ -1042,6 +1082,7 @@ break2: break; } progressmeter(1); + progress = oprogress; if (closefunc != NULL) (*closefunc)(fout); (void)signal(SIGINT, oldintr); @@ -1061,16 +1102,19 @@ break2: ut.actime = time(NULL); ut.modtime = mtime; if (utime(local, &ut) == -1) - printf("Can't change modification time on %s to %s", + printf( + "Can't change modification time on %s to %s", local, asctime(localtime(&mtime))); } } } return; + abort: /* abort using RFC959 recommended IP,SYNC sequence */ + progress = oprogress; if (oldintp) (void)signal(SIGPIPE, oldintp); (void)signal(SIGINT, SIG_IGN); @@ -1134,7 +1178,8 @@ initconn() if (sscanf(pasv, "%d,%d,%d,%d,%d,%d", &a0, &a1, &a2, &a3, &p0, &p1) != 6) { - puts("Passive mode address scan failure. Shouldn't happen!"); + puts( +"Passive mode address scan failure. Shouldn't happen!"); goto bad; } @@ -1232,7 +1277,9 @@ dataconn(lmode) const char *lmode; { struct sockaddr_in from; - int s, fromlen = sizeof(from), tos; + int s, fromlen, tos; + + fromlen = sizeof(from); if (passivemode) return (fdopen(data, lmode)); @@ -1405,7 +1452,7 @@ proxtrans(cmd, local, remote) } pswitch(0); if (!connected) { - puts("No primary connection"); + puts("No primary connection."); pswitch(1); code = -1; return; @@ -1573,6 +1620,14 @@ abort_remote(din) int nfnd; struct fd_set mask; + if (cout == NULL) { + warnx("Lost control connection for abort."); + if (ptabflg) + code = -1; + lostpeer(); + return; + } + /* * send IAC in urgent mode instead of DM because 4.3BSD places oob mark * after urgent byte rather than before as is protocol now diff --git a/usr.bin/ftp/ftp_var.h b/usr.bin/ftp/ftp_var.h index 50468d7891f..2ab7545fc44 100644 --- a/usr.bin/ftp/ftp_var.h +++ b/usr.bin/ftp/ftp_var.h @@ -1,5 +1,5 @@ -/* $OpenBSD: ftp_var.h,v 1.8 1997/02/18 18:04:30 kstailey Exp $ */ -/* $NetBSD: ftp_var.h,v 1.13 1997/02/01 10:45:05 lukem Exp $ */ +/* $OpenBSD: ftp_var.h,v 1.9 1997/03/14 04:32:16 millert Exp $ */ +/* $NetBSD: ftp_var.h,v 1.14 1997/03/13 06:23:19 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -57,6 +57,7 @@ #define FTP_PORT 21 /* default if getservbyname("ftp/tcp") fails */ #define HTTP_PORT 80 /* default if getservbyname("http/tcp") fails */ +#define PAGER "more" /* default pager if $PAGER isn't set */ /* * Options and other state info. @@ -68,7 +69,6 @@ int sendport; /* use PORT cmd for each data connection */ int verbose; /* print messages coming back from server */ int connected; /* connected to server */ int fromatty; /* input is from a terminal */ -int use_editline; /* use the editline(3) routine for input */ int interactive; /* interactively prompt on m* cmds */ int confirmrest; /* confirm rest of current m* cmd */ int debug; /* debugging level */ diff --git a/usr.bin/ftp/main.c b/usr.bin/ftp/main.c index 3771f115c0b..4c720d1e822 100644 --- a/usr.bin/ftp/main.c +++ b/usr.bin/ftp/main.c @@ -1,5 +1,5 @@ -/* $OpenBSD: main.c,v 1.21 1997/02/18 18:04:31 kstailey Exp $ */ -/* $NetBSD: main.c,v 1.17 1997/02/01 10:45:07 lukem Exp $ */ +/* $OpenBSD: main.c,v 1.22 1997/03/14 04:32:17 millert Exp $ */ +/* $NetBSD: main.c,v 1.18 1997/03/13 06:23:19 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.21 1997/02/18 18:04:31 kstailey Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.22 1997/03/14 04:32:17 millert Exp $"; #endif #endif /* not lint */ @@ -92,9 +92,11 @@ main(argc, argv) preserve = 1; verbose = 0; progress = 0; +#ifndef SMALLFTP + editing = 0; +#endif mark = HASHBYTES; marg_sl = sl_init(); - use_editline = 1; /* use editline if possible */ cp = strrchr(argv[0], '/'); cp = (cp == NULL) ? argv[0] : cp + 1; @@ -102,8 +104,14 @@ main(argc, argv) passivemode = 1; fromatty = isatty(fileno(stdin)); - if (fromatty) + if (fromatty) { verbose = 1; /* verbose if from a tty */ +#ifndef SMALLFTP + editing = 1; /* editing mode on if from a tty */ +#endif + } + if (isatty(fileno(stdout))) + progress = 1; /* progress bar on if going to a tty */ while ((ch = getopt(argc, argv, "adeginpPr:tvV")) != -1) { switch (ch) { @@ -117,7 +125,9 @@ main(argc, argv) break; case 'e': - use_editline = 0; +#ifndef SMALLFTP + editing = 0; +#endif break; case 'g': @@ -189,9 +199,7 @@ main(argc, argv) } #ifndef SMALLFTP - editing = 0; /* command line editing off */ - if (fromatty && use_editline) { - editing = 1; /* editing mode on if a tty */ + if (fromatty) { el = el_init(__progname, stdin, stdout); /* init editline */ hist = history_init(); /* init the builtin history */ @@ -337,7 +345,7 @@ cmdscanner(top) break; line[num] = '\0'; } else if (num == sizeof(line) - 2) { - puts("sorry, input line too long"); + puts("sorry, input line too long."); while ((num = getchar()) != '\n' && num != EOF) /* void */; break; @@ -353,7 +361,7 @@ cmdscanner(top) if (num == 0) break; } else if (num >= sizeof(line)) { - puts("sorry, input line too long"); + puts("sorry, input line too long."); break; } memcpy(line, buf, num); @@ -375,11 +383,11 @@ cmdscanner(top) #endif /* !SMALLFTP */ c = getcmd(margv[0]); if (c == (struct cmd *)-1) { - puts("?Ambiguous command"); + puts("?Ambiguous command."); continue; } if (c == 0) { - puts("?Invalid command"); + puts("?Invalid command."); continue; } if (c->c_conn && !connected) { @@ -652,7 +660,7 @@ void usage() { (void)fprintf(stderr, - "usage: %s [-adginprtvV] [host [port]]\n" + "usage: %s [-adeginprtvV] [host [port]]\n" " %s host:path[/]\n" " %s ftp://host[:port]/path[/]\n" " %s http://host[:port]/file\n", diff --git a/usr.bin/ftp/ruserpass.c b/usr.bin/ftp/ruserpass.c index ebec996c0f8..48c6b24ce93 100644 --- a/usr.bin/ftp/ruserpass.c +++ b/usr.bin/ftp/ruserpass.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ruserpass.c,v 1.5 1997/02/03 01:05:44 millert Exp $ */ -/* $NetBSD: ruserpass.c,v 1.11 1997/01/19 14:19:16 lukem Exp $ */ +/* $OpenBSD: ruserpass.c,v 1.6 1997/03/14 04:32:17 millert Exp $ */ +/* $NetBSD: ruserpass.c,v 1.12 1997/03/13 06:23:20 lukem Exp $ */ /* * Copyright (c) 1985, 1993, 1994 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95"; #else -static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.5 1997/02/03 01:05:44 millert Exp $"; +static char rcsid[] = "$OpenBSD: ruserpass.c,v 1.6 1997/03/14 04:32:17 millert Exp $"; #endif #endif /* not lint */ @@ -196,7 +196,7 @@ next: } if (macnum == 16) { puts( -"Limit of 16 macros have already been defined"); +"Limit of 16 macros have already been defined."); goto bad; } tmp = macros[macnum].mac_name; @@ -244,7 +244,7 @@ next: tmp++; } if (tmp == macbuf + 4096) { - puts("4K macro buffer exceeded"); + puts("4K macro buffer exceeded."); goto bad; } break; diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index 63f2e1e625a..b0a8dec3601 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -1,5 +1,5 @@ -/* $OpenBSD: util.c,v 1.3 1997/02/05 04:55:21 millert Exp $ */ -/* $NetBSD: util.c,v 1.4 1997/02/01 11:26:34 lukem Exp $ */ +/* $OpenBSD: util.c,v 1.4 1997/03/14 04:32:18 millert Exp $ */ +/* $NetBSD: util.c,v 1.5 1997/03/13 06:23:21 lukem Exp $ */ /* * Copyright (c) 1985, 1989, 1993, 1994 @@ -35,7 +35,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: util.c,v 1.3 1997/02/05 04:55:21 millert Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.4 1997/03/14 04:32:18 millert Exp $"; #endif /* not lint */ /* @@ -89,8 +89,8 @@ setpeer(argc, argv) if (argc > 2) { port = atoi(argv[2]); if (port <= 0) { - printf("%s: bad port number-- %s\n", argv[1], argv[2]); - printf ("usage: %s host-name [port]\n", argv[0]); + printf("%s: bad port number '%s'.\n", argv[1], argv[2]); + printf("usage: %s host-name [port]\n", argv[0]); code = -1; return; } @@ -124,9 +124,9 @@ setpeer(argc, argv) if (command("SYST") == COMPLETE && overbose) { char *cp, c; c = 0; - cp = strchr(reply_string+4, ' '); + cp = strchr(reply_string + 4, ' '); if (cp == NULL) - cp = strchr(reply_string+4, '\r'); + cp = strchr(reply_string + 4, '\r'); if (cp) { if (cp[-1] == '.') cp--; @@ -170,7 +170,7 @@ setpeer(argc, argv) } /* - * `Another' gets another argument, and stores the new argc and argv. + * `another' gets another argument, and stores the new argc and argv. * It reverts to the top level (via main.c's intr()) on EOF/error. * * Returns false if no new arguments have been added. @@ -184,7 +184,7 @@ another(pargc, pargv, prompt) int len = strlen(line), ret; if (len >= sizeof(line) - 3) { - puts("sorry, arguments too long"); + puts("sorry, arguments too long."); intr(); } printf("(%s) ", prompt); @@ -201,10 +201,16 @@ another(pargc, pargv, prompt) return (ret); } +/* + * glob files given in argv[] from the remote server. + * if errbuf isn't NULL, store error messages there instead + * of writing to the screen. + */ char * -remglob(argv, doswitch) +remglob(argv, doswitch, errbuf) char *argv[]; int doswitch; + char **errbuf; { char temp[MAXPATHLEN]; static char buf[MAXPATHLEN]; @@ -214,9 +220,8 @@ remglob(argv, doswitch) char *cp, *mode; if (!mflag) { - if (!doglob) { + if (!doglob) args = NULL; - } else { if (ftemp) { (void)fclose(ftemp); @@ -248,32 +253,41 @@ remglob(argv, doswitch) if (temp[len-1] != '/') temp[len++] = '/'; (void)strcpy(&temp[len], TMPFILE); -; if ((fd = mkstemp(temp)) < 0) { warn("unable to create temporary file %s", temp); return (NULL); } close(fd); - oldverbose = verbose, verbose = 0; - oldhash = hash, hash = 0; - if (doswitch) { + oldverbose = verbose; + verbose = (errbuf != NULL) ? -1 : 0; + oldhash = hash; + hash = 0; + if (doswitch) pswitch(!proxy); - } for (mode = "w"; *++argv != NULL; mode = "a") - recvrequest ("NLST", temp, *argv, mode, 0); - if (doswitch) { - pswitch(!proxy); - } - verbose = oldverbose; hash = oldhash; + recvrequest("NLST", temp, *argv, mode, 0); + if ((code / 100) != COMPLETE) { + if (errbuf != NULL) + *errbuf = reply_string; + } + if (doswitch) + pswitch(!proxy); + verbose = oldverbose; + hash = oldhash; ftemp = fopen(temp, "r"); (void)unlink(temp); if (ftemp == NULL) { - puts("can't find list of remote files, oops"); + if (errbuf == NULL) + puts("can't find list of remote files, oops."); + else + *errbuf = + "can't find list of remote files, oops."; return (NULL); } } if (fgets(buf, sizeof(buf), ftemp) == NULL) { - (void)fclose(ftemp), ftemp = NULL; + (void)fclose(ftemp); + ftemp = NULL; return (NULL); } if ((cp = strchr(buf, '\n')) != NULL) @@ -298,11 +312,11 @@ confirm(cmd, file) return (0); case 'p': interactive = 0; - puts("Interactive mode: off"); + puts("Interactive mode: off."); break; case 'a': confirmrest = 1; - printf("Prompting off for duration of %s\n", cmd); + printf("Prompting off for duration of %s.\n", cmd); break; } return (1); @@ -355,7 +369,7 @@ remotesize(file, noisy) if (command("SIZE %s", file) == COMPLETE) sscanf(reply_string, "%*s %qd", &size); else if (noisy && debug == 0) - printf("%s\n", reply_string); + puts(reply_string); verbose = overbose; return (size); } @@ -390,7 +404,7 @@ remotemodtime(file, noisy) timebuf.tm_isdst = -1; rtime = mktime(&timebuf); if (rtime == -1 && (noisy || debug != 0)) - printf("Can't convert %s to a time\n", reply_string); + printf("Can't convert %s to a time.\n", reply_string); else rtime += timebuf.tm_gmtoff; /* conv. local -> GMT */ } else if (noisy && debug == 0) -- 2.20.1