- implement "mreget"; as per "mget" but uses "reget" instead of "get"

- add -N netrc and $NETRC, as methods to select an alternative .netrc file
- cache local user name and home directory for further use
- in mget(), use docase() instead of a local version to do the case
  conversion.
This commit is contained in:
lukem 2000-11-15 00:10:59 +00:00
parent 661711dff9
commit ecd3d78091
8 changed files with 148 additions and 79 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.91 2000/10/11 14:46:03 is Exp $ */
/* $NetBSD: cmds.c,v 1.92 2000/11/15 00:10:59 lukem Exp $ */
/*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@ -107,7 +107,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: cmds.c,v 1.91 2000/10/11 14:46:03 is Exp $");
__RCSID("$NetBSD: cmds.c,v 1.92 2000/11/15 00:10:59 lukem Exp $");
#endif
#endif /* not lint */
@ -552,6 +552,8 @@ get(int argc, char *argv[])
/*
* Receive one file.
* If restartit is 1, restart the xfer always.
* If restartit is -1, restart the xfer only if the remote file is newer.
*/
int
getit(int argc, char *argv[], int restartit, const char *mode)
@ -664,8 +666,9 @@ void
mget(int argc, char *argv[])
{
sigfunc oldintr;
int ch, ointer;
char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN];
int ointer;
char *cp, *tp;
int restartit;
if (argc == 0 ||
(argc == 1 && !another(&argc, &argv, "remote-files"))) {
@ -675,6 +678,16 @@ mget(int argc, char *argv[])
}
mname = argv[0];
mflag = 1;
restart_point = 0;
restartit = 0;
if (strcmp(argv[0], "mreget") == 0) {
if (! features[FEAT_REST_STREAM]) {
fprintf(ttyout,
"Restart is not supported by the remote server.\n");
return;
}
restartit = 1;
}
oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1))
mabort();
@ -683,30 +696,32 @@ mget(int argc, char *argv[])
mflag = 0;
continue;
}
if (mflag && confirm(argv[0], cp)) {
tp = cp;
if (mcase) {
for (tp2 = tmpbuf; (ch = *tp++) != 0; )
*tp2++ = isupper(ch) ? tolower(ch) : ch;
*tp2 = '\0';
tp = tmpbuf;
}
if (ntflag) {
tp = dotrans(tp);
}
if (mapflag) {
tp = domap(tp);
}
recvrequest("RETR", tp, cp, "w",
tp != cp || !interactive, 1);
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
if (confirm("Continue with", "mget")) {
mflag++;
}
interactive = ointer;
}
if (! mflag || !confirm(argv[0], cp))
continue;
tp = cp;
if (mcase)
tp = docase(tp);
if (ntflag)
tp = dotrans(tp);
if (mapflag)
tp = domap(tp);
if (restartit) {
struct stat stbuf;
if (stat(tp, &stbuf) == 0)
restart_point = stbuf.st_size;
else
warn("stat %s", tp);
}
recvrequest("RETR", tp, cp, restart_point ? "r+w" : "w",
tp != cp || !interactive, 1);
restart_point = 0;
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
if (confirm("Continue with", "mget"))
mflag++;
interactive = ointer;
}
}
(void)xsignal(SIGINT, oldintr);
@ -1136,7 +1151,7 @@ lcd(int argc, char *argv[])
code = -1;
if (argc == 1) {
argc++;
argv[1] = home;
argv[1] = localhome;
}
if (argc != 2) {
fprintf(ttyout, "usage: %s [local-directory]\n", argv[0]);

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmdtab.c,v 1.38 2000/09/14 13:48:33 lukem Exp $ */
/* $NetBSD: cmdtab.c,v 1.39 2000/11/15 00:10:59 lukem Exp $ */
/*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@ -74,7 +74,7 @@
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: cmdtab.c,v 1.38 2000/09/14 13:48:33 lukem Exp $");
__RCSID("$NetBSD: cmdtab.c,v 1.39 2000/11/15 00:10:59 lukem Exp $");
#endif
#endif /* not lint */
@ -116,6 +116,7 @@ char lshelp[] = "list contents of remote path";
char macdefhelp[] = "define a macro";
char mdeletehelp[] = "delete multiple files";
char mgethelp[] = "get multiple files";
char mregethelp[] = "get multiple files restarting at end of local file";
char fgethelp[] = "get files using a localfile as a source of names";
char mkdirhelp[] = "make directory on the remote machine";
char mlshelp[] = "list contents of multiple remote directories";
@ -232,6 +233,7 @@ struct cmd cmdtab[] = {
{ "modtime", modtimehelp, 0, 1, 1, CMPL(r) modtime },
{ "more", pagehelp, 1, 1, 1, CMPL(r) page },
{ "mput", mputhelp, 1, 1, 1, CMPL(L) mput },
{ "mreget", mregethelp, 1, 1, 1, CMPL(R) mget },
{ "msend", mputhelp, 1, 1, 1, CMPL(L) mput },
{ "newer", newerhelp, 1, 1, 1, CMPL(r) newer },
{ "nlist", lshelp, 1, 1, 1, CMPL(rl) ls },

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ftp.1,v 1.73 2000/09/28 12:26:19 lukem Exp $
.\" $NetBSD: ftp.1,v 1.74 2000/11/15 00:10:59 lukem Exp $
.\"
.\" Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -68,7 +68,7 @@
.\"
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
.\"
.Dd September 28, 2000
.Dd November 15, 2000
.Dt FTP 1
.Os
.Sh NAME
@ -79,6 +79,9 @@ Internet file transfer program
.Nm ""
.Op Fl AadefginpRtvV
.Bk -words
.Op Fl N Ar netrc
.Ek
.Bk -words
.Op Fl o Ar output
.Ek
.Bk -words
@ -194,6 +197,14 @@ If no entry exists,
will prompt for the remote machine login name (default is the user
identity on the local machine), and, if necessary, prompt for a password
and an account with which to login.
.It Fl N Ar netrc
Use
.Ar netrc
instead of
.Pa ~/.netrc .
Refer to
.Sx THE .netrc FILE
for more information.
.It Fl o Ar output
When auto-fetching files, save the contents in
.Ar output .
@ -351,7 +362,10 @@ and exit
An end of file will also terminate the session and exit.
.It Ic case
Toggle remote computer file name case mapping during
.Ic get ,
.Ic mget
and
.Ic mput
commands.
When
.Ic case
@ -517,9 +531,10 @@ are used while transferring the file.
.It Ic glob
Toggle filename expansion for
.Ic mdelete ,
.Ic mget
.Ic mget ,
.Ic mput ,
and
.Ic mput .
.Ic mreget .
If globbing is turned off with
.Ic glob ,
the file name arguments
@ -529,9 +544,10 @@ Globbing for
is done as in
.Xr csh 1 .
For
.Ic mdelete
.Ic mdelete ,
.Ic mget ,
and
.Ic mget ,
.Ic mreget ,
each remote file name is expanded
separately on the remote machine and the lists are not merged.
Expansion of a directory name is likely to be
@ -540,9 +556,10 @@ the exact result depends on the foreign operating system and ftp server,
and can be previewed by doing
.Ql mls remote-files \-
Note:
.Ic mget
and
.Ic mget ,
.Ic mput
and
.Ic mreget
are not meant to transfer
entire directory subtrees of files.
That can be done by
@ -710,6 +727,13 @@ Resulting file names will then be processed according to
and
.Ic nmap
settings.
.It Ic mreget Ar remote-files
As per
.Ic mget ,
but performs a
.Ic reget
instead of
.Ic get .
.It Ic msend Ar local-files
A synonym for
.Ic mput .
@ -1712,7 +1736,12 @@ The
.Pa .netrc
file contains login and initialization information
used by the auto-login process.
It resides in the user's home directory.
It resides in the user's home directory,
unless overridden with the
.Fl N Ar netrc
option, or specified in the
.Ev NETRC
environment variable.
The following tokens are recognized; they may be separated by spaces,
tabs, or new-lines:
.Bl -tag -width password
@ -1939,6 +1968,10 @@ lookup of
For default location of a
.Pa .netrc
file, if one exists.
.It Ev NETRC
An alternate location of the
.Pa .netrc
file.
.It Ev PAGER
Used by various commands to display files.
Defaults to

View File

@ -1,4 +1,4 @@
/* $NetBSD: ftp_var.h,v 1.58 2000/08/01 22:47:28 lukem Exp $ */
/* $NetBSD: ftp_var.h,v 1.59 2000/11/15 00:11:03 lukem Exp $ */
/*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@ -315,7 +315,9 @@ GLOBAL int macnum; /* number of defined macros */
GLOBAL struct macel macros[16];
GLOBAL char macbuf[4096];
GLOBAL char home[MAXPATHLEN]; /* home directory (for lcd) */
GLOBAL char *localhome; /* local home directory */
GLOBAL char *localname; /* local user name */
GLOBAL char netrc[MAXPATHLEN]; /* path to .netrc file */
GLOBAL char reply_string[BUFSIZ]; /* first line of previous reply */
GLOBAL void (*reply_callback)(const char *);
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.73 2000/07/18 07:16:56 lukem Exp $ */
/* $NetBSD: main.c,v 1.74 2000/11/15 00:11:03 lukem Exp $ */
/*-
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
@ -108,7 +108,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
__RCSID("$NetBSD: main.c,v 1.73 2000/07/18 07:16:56 lukem Exp $");
__RCSID("$NetBSD: main.c,v 1.74 2000/11/15 00:11:03 lukem Exp $");
#endif
#endif /* not lint */
@ -143,7 +143,7 @@ int
main(int argc, char *argv[])
{
int ch, rval;
struct passwd *pw = NULL;
struct passwd *pw;
char *cp, *ep, *anonuser, *anonpass, *upload_path;
int dumbterm, s, len, isupload;
@ -188,6 +188,11 @@ main(int argc, char *argv[])
isupload = 0;
reply_callback = NULL;
netrc[0] = '\0';
cp = getenv("NETRC");
if (cp != NULL && strlcpy(netrc, cp, sizeof(netrc)) >= sizeof(netrc))
errx(1, "$NETRC `%s': %s", cp, strerror(ENAMETOOLONG));
/*
* Get the default socket buffer sizes if we don't already have them.
* It doesn't matter which socket we do this to, because on the first
@ -271,7 +276,7 @@ main(int argc, char *argv[])
}
}
while ((ch = getopt(argc, argv, "Aadefgino:pP:r:RtT:u:vV")) != -1) {
while ((ch = getopt(argc, argv, "AadefginN:o:pP:r:RtT:u:vV")) != -1) {
switch (ch) {
case 'A':
activefallback = 0;
@ -309,6 +314,13 @@ main(int argc, char *argv[])
autologin = 0;
break;
case 'N':
if (strlcpy(netrc, optarg, sizeof(netrc))
>= sizeof(netrc))
errx(1, "%s: %s", optarg,
strerror(ENAMETOOLONG));
break;
case 'o':
outfile = optarg;
if (strcmp(outfile, "-") == 0)
@ -394,21 +406,38 @@ main(int argc, char *argv[])
proxy = 0; /* proxy 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.
* Cache the user name and home directory.
*/
localhome = NULL;
localname = NULL;
anonuser = "anonymous";
cp = getenv("HOME");
if (! EMPTYSTRING(cp))
localhome = xstrdup(cp);
pw = NULL;
cp = getlogin();
if (cp != NULL)
pw = getpwnam(cp);
if (pw == NULL)
pw = getpwuid(getuid());
if (pw != NULL) {
(void)strlcpy(home, pw->pw_dir, sizeof(home));
anonuser = pw->pw_name;
} else {
(void)strlcpy(home, "/", sizeof(home));
anonuser = "anonymous";
if (localhome == NULL && !EMPTYSTRING(pw->pw_dir))
localhome = xstrdup(pw->pw_dir);
localname = xstrdup(pw->pw_name);
anonuser = localname;
}
if (netrc[0] == '\0' && localhome != NULL) {
if (strlcpy(netrc, localhome, sizeof(netrc)) >= sizeof(netrc) ||
strlcat(netrc, "/.netrc", sizeof(netrc)) >= sizeof(netrc)) {
warnx("%s/.netrc: %s", localhome,
strerror(ENAMETOOLONG));
netrc[0] = '\0';
}
}
if (localhome == NULL)
localhome = xstrdup("/");
/*
* Every anonymous FTP server I've encountered will accept the
@ -972,7 +1001,7 @@ void
usage(void)
{
(void)fprintf(stderr,
"usage: %s [-AadefginpRtvV] [-o outfile] [-P port] [-r retry]\n"
"usage: %s [-AadefginpRtvV] [-N netrc] [-o outfile] [-P port] [-r retry]\n"
" [-T dir,max[,inc][[user@]host [port]]] [host:path[/]]\n"
" [file:///file] [ftp://[user[:pass]@]host[:port]/path[/]]\n"
" [http://[user[:pass]@]host[:port]/path] [...]\n"

View File

@ -1,4 +1,4 @@
/* $NetBSD: ruserpass.c,v 1.27 2000/07/18 06:47:02 lukem Exp $ */
/* $NetBSD: ruserpass.c,v 1.28 2000/11/15 00:11:04 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
__RCSID("$NetBSD: ruserpass.c,v 1.27 2000/07/18 06:47:02 lukem Exp $");
__RCSID("$NetBSD: ruserpass.c,v 1.28 2000/11/15 00:11:04 lukem Exp $");
#endif
#endif /* not lint */
@ -85,25 +85,19 @@ static struct toktab {
int
ruserpass(const char *host, const char **aname, const char **apass,
const char **aacct)
const char **aacct)
{
char *hdir, buf[BUFSIZ], *tmp;
char *tmp;
char myname[MAXHOSTNAMELEN + 1], *mydomain;
int t, i, c, usedefault = 0;
struct stat stb;
hdir = getenv("HOME");
if (hdir == NULL)
hdir = ".";
if (strlcpy(buf, hdir, sizeof(buf)) >= sizeof(buf) ||
strlcat(buf, "/.netrc", sizeof(buf)) >= sizeof(buf)) {
warnx("%s/.netrc: %s", hdir, strerror(ENAMETOOLONG));
if (netrc[0] == '\0')
return (0);
}
cfile = fopen(buf, "r");
cfile = fopen(netrc, "r");
if (cfile == NULL) {
if (errno != ENOENT)
warn("%s", buf);
warn("%s", netrc);
return (0);
}
if (gethostname(myname, sizeof(myname)) < 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.102 2000/09/08 11:54:53 lukem Exp $ */
/* $NetBSD: util.c,v 1.103 2000/11/15 00:11:04 lukem Exp $ */
/*-
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.102 2000/09/08 11:54:53 lukem Exp $");
__RCSID("$NetBSD: util.c,v 1.103 2000/11/15 00:11:04 lukem Exp $");
#endif /* not lint */
/*
@ -96,7 +96,6 @@ __RCSID("$NetBSD: util.c,v 1.102 2000/09/08 11:54:53 lukem Exp $");
#include <signal.h>
#include <limits.h>
#include <netdb.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -366,7 +365,6 @@ ftp_login(const char *host, const char *user, const char *pass)
{
char tmp[80];
const char *acct;
struct passwd *pw;
int n, aflag, rval, freeuser, freepass, freeacct;
acct = NULL;
@ -397,12 +395,8 @@ ftp_login(const char *host, const char *user, const char *pass)
}
while (user == NULL) {
const char *myname = getlogin();
if (myname == NULL && (pw = getpwuid(getuid())) != NULL)
myname = pw->pw_name;
if (myname)
fprintf(ttyout, "Name (%s:%s): ", host, myname);
if (localname)
fprintf(ttyout, "Name (%s:%s): ", host, localname);
else
fprintf(ttyout, "Name (%s): ", host);
*tmp = '\0';
@ -415,7 +409,7 @@ ftp_login(const char *host, const char *user, const char *pass)
tmp[strlen(tmp) - 1] = '\0';
freeuser = 0;
if (*tmp == '\0')
user = myname;
user = localname;
else
user = tmp;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: version.h,v 1.21 2000/09/28 12:29:24 lukem Exp $ */
/* $NetBSD: version.h,v 1.22 2000/11/15 00:11:04 lukem Exp $ */
/*-
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
@ -40,5 +40,5 @@
#endif
#ifndef FTP_VERSION
#define FTP_VERSION "20000928"
#define FTP_VERSION "20001115"
#endif