Add support for 'ftp -u url file ...', to upload a list of files to given url.
Mostly based on [bin/10019] by Scott Aaron Bamford <sab@ansic.net>
This commit is contained in:
parent
bb159432ef
commit
413a4004df
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: extern.h,v 1.55 2000/05/29 14:57:27 itojun Exp $ */
|
/* $NetBSD: extern.h,v 1.56 2000/05/31 14:23:57 lukem Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
|
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
|
||||||
@ -113,6 +113,7 @@ void ai_unmapped(struct addrinfo *);
|
|||||||
void alarmtimer(int);
|
void alarmtimer(int);
|
||||||
int another(int *, char ***, const char *);
|
int another(int *, char ***, const char *);
|
||||||
int auto_fetch(int, char **);
|
int auto_fetch(int, char **);
|
||||||
|
int auto_put(int, char **, const char *);
|
||||||
void blkfree(char **);
|
void blkfree(char **);
|
||||||
void cd(int, char **);
|
void cd(int, char **);
|
||||||
void cdup(int, char **);
|
void cdup(int, char **);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: fetch.c,v 1.113 2000/05/29 14:57:27 itojun Exp $ */
|
/* $NetBSD: fetch.c,v 1.114 2000/05/31 14:23:58 lukem Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
|
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
|
||||||
@ -7,6 +7,9 @@
|
|||||||
* This code is derived from software contributed to The NetBSD Foundation
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
* by Luke Mewburn.
|
* by Luke Mewburn.
|
||||||
*
|
*
|
||||||
|
* This code is derived from software contributed to The NetBSD Foundation
|
||||||
|
* by Scott Aaron Bamford.
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@ -38,7 +41,7 @@
|
|||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
__RCSID("$NetBSD: fetch.c,v 1.113 2000/05/29 14:57:27 itojun Exp $");
|
__RCSID("$NetBSD: fetch.c,v 1.114 2000/05/31 14:23:58 lukem Exp $");
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1797,3 +1800,80 @@ auto_fetch(int argc, char *argv[])
|
|||||||
disconnect(0, NULL);
|
disconnect(0, NULL);
|
||||||
return (rval);
|
return (rval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
auto_put(int argc, char **argv, const char *uploadserver)
|
||||||
|
{
|
||||||
|
char *uargv[4], *path, *pathsep;
|
||||||
|
int uargc, rval, len;
|
||||||
|
|
||||||
|
uargc = 0;
|
||||||
|
uargv[uargc++] = "mput";
|
||||||
|
uargv[uargc++] = argv[0];
|
||||||
|
uargv[2] = uargv[3] = NULL;
|
||||||
|
pathsep = NULL;
|
||||||
|
rval = 1;
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
fprintf(ttyout, "auto_put: target `%s'\n", uploadserver);
|
||||||
|
|
||||||
|
path = xstrdup(uploadserver);
|
||||||
|
len = strlen(path);
|
||||||
|
if (path[len - 1] != '/' && path[len - 1] != ':') {
|
||||||
|
/*
|
||||||
|
* make sure we always pass a directory to auto_fetch
|
||||||
|
*/
|
||||||
|
if (argc > 1) { /* more than one file to upload */
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = strlen(uploadserver) + 2; /* path + "/" + "\0" */
|
||||||
|
free(path);
|
||||||
|
path = (char *)xmalloc(len);
|
||||||
|
(void)strlcpy(path, uploadserver, len);
|
||||||
|
(void)strlcat(path, "/", len);
|
||||||
|
} else { /* single file to upload */
|
||||||
|
uargv[0] = "put";
|
||||||
|
pathsep = strrchr(path, '/');
|
||||||
|
if (pathsep == NULL) {
|
||||||
|
pathsep = strrchr(path, ':');
|
||||||
|
if (pathsep == NULL) {
|
||||||
|
warnx("Invalid URL `%s'", path);
|
||||||
|
goto cleanup_auto_put;
|
||||||
|
}
|
||||||
|
pathsep++;
|
||||||
|
uargv[2] = xstrdup(pathsep);
|
||||||
|
pathsep[0] = '/';
|
||||||
|
} else
|
||||||
|
uargv[2] = xstrdup(pathsep + 1);
|
||||||
|
pathsep[1] = '\0';
|
||||||
|
uargc++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (debug)
|
||||||
|
fprintf(ttyout, "autoput: url `%s' argv[2] `%s'\n",
|
||||||
|
path, uargv[2] ? uargv[2] : "<null>");
|
||||||
|
|
||||||
|
/* connect and cwd */
|
||||||
|
rval = auto_fetch(1, &path);
|
||||||
|
free(path);
|
||||||
|
if(rval >= 0)
|
||||||
|
goto cleanup_auto_put;
|
||||||
|
|
||||||
|
/* XXX : is this the best way? */
|
||||||
|
if (uargc == 3) {
|
||||||
|
uargv[1] = argv[0];
|
||||||
|
put(uargc, uargv);
|
||||||
|
goto cleanup_auto_put;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(; argv[0] != NULL; argv++) {
|
||||||
|
uargv[1] = argv[0];
|
||||||
|
mput(uargc, uargv);
|
||||||
|
}
|
||||||
|
rval = 0;
|
||||||
|
|
||||||
|
cleanup_auto_put:
|
||||||
|
FREEPTR(uargv[2]);
|
||||||
|
return (rval);
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.\" $NetBSD: ftp.1,v 1.66 2000/05/31 10:25:15 lukem Exp $
|
.\" $NetBSD: ftp.1,v 1.67 2000/05/31 14:23:58 lukem Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
|
.\" Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
@ -68,7 +68,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
|
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
|
||||||
.\"
|
.\"
|
||||||
.Dd May 28, 2000
|
.Dd June 1, 2000
|
||||||
.Dt FTP 1
|
.Dt FTP 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -118,6 +118,15 @@ Internet file transfer program
|
|||||||
.Op http://[\fIuser\fR[:\fIpassword\fR]@]\fIhost\fR[:\fIport\fR]/\fIpath\fR
|
.Op http://[\fIuser\fR[:\fIpassword\fR]@]\fIhost\fR[:\fIport\fR]/\fIpath\fR
|
||||||
.Ek
|
.Ek
|
||||||
.Op Ar \&.\&.\&.
|
.Op Ar \&.\&.\&.
|
||||||
|
.Nm ""
|
||||||
|
.Fl u Ar url
|
||||||
|
.\".Ar ftp://[\fIuser\fR[:\fIpassword\fR]@]\fIhost\fR[:\fIport\fR]/\fIpath\fR[/[file]]
|
||||||
|
.\"|
|
||||||
|
.\".Ar [\fIuser\fR@]\fIhost\fR:[\fIpath\fR][/[\fIfile\fR]]
|
||||||
|
.Bk -words
|
||||||
|
file
|
||||||
|
.Ek
|
||||||
|
.Op Ar \&.\&.\&.
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
is the user interface to the Internet standard File Transfer Protocol.
|
is the user interface to the Internet standard File Transfer Protocol.
|
||||||
@ -238,6 +247,15 @@ bytes/second.
|
|||||||
Refer to
|
Refer to
|
||||||
.Ic rate
|
.Ic rate
|
||||||
for more information.
|
for more information.
|
||||||
|
.It Fl u Ar url file Op \&.\&.\&.
|
||||||
|
Upload files on the command line to
|
||||||
|
.Ar url
|
||||||
|
where
|
||||||
|
.Ar url
|
||||||
|
is one of the ftp URL types as supported by auto-fetch
|
||||||
|
(with an optional target filename for single file uploads), and
|
||||||
|
.Ar file
|
||||||
|
is one or more local files to be uploaded.
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Enable
|
Enable
|
||||||
.Ic verbose
|
.Ic verbose
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: main.c,v 1.70 2000/05/01 10:35:19 lukem Exp $ */
|
/* $NetBSD: main.c,v 1.71 2000/05/31 14:23:59 lukem Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
|
* Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
|
||||||
@ -108,7 +108,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: main.c,v 1.70 2000/05/01 10:35:19 lukem Exp $");
|
__RCSID("$NetBSD: main.c,v 1.71 2000/05/31 14:23:59 lukem Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -144,8 +144,8 @@ main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int ch, rval;
|
int ch, rval;
|
||||||
struct passwd *pw = NULL;
|
struct passwd *pw = NULL;
|
||||||
char *cp, *ep, *anonuser, *anonpass;
|
char *cp, *ep, *anonuser, *anonpass, *upload_path;
|
||||||
int dumbterm, s, len;
|
int dumbterm, s, len, isupload;
|
||||||
|
|
||||||
ftpport = "ftp";
|
ftpport = "ftp";
|
||||||
httpport = "http";
|
httpport = "http";
|
||||||
@ -184,6 +184,8 @@ main(int argc, char *argv[])
|
|||||||
epsv4 = 0;
|
epsv4 = 0;
|
||||||
#endif
|
#endif
|
||||||
epsv4bad = 0;
|
epsv4bad = 0;
|
||||||
|
upload_path = NULL;
|
||||||
|
isupload = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the default socket buffer sizes if we don't already have them.
|
* Get the default socket buffer sizes if we don't already have them.
|
||||||
@ -268,7 +270,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "Aadefgino:pP:r:RtT:vV")) != -1) {
|
while ((ch = getopt(argc, argv, "Aadefgino:pP:r:RtT:u:vV")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'A':
|
case 'A':
|
||||||
activefallback = 0;
|
activefallback = 0;
|
||||||
@ -361,6 +363,16 @@ main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'u':
|
||||||
|
{
|
||||||
|
/* XXX : if i move this under 'T' we get a segv. */
|
||||||
|
isupload = 1;
|
||||||
|
interactive = 0;
|
||||||
|
upload_path = xstrdup(optarg);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
progress = verbose = 1;
|
progress = verbose = 1;
|
||||||
break;
|
break;
|
||||||
@ -439,7 +451,11 @@ main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
if (strchr(argv[0], ':') != NULL && ! isipv6addr(argv[0])) {
|
if (isupload) {
|
||||||
|
rval = auto_put(argc, argv, upload_path);
|
||||||
|
exit(rval);
|
||||||
|
} else if (strchr(argv[0], ':') != NULL
|
||||||
|
&& ! isipv6addr(argv[0])) {
|
||||||
rval = auto_fetch(argc, argv);
|
rval = auto_fetch(argc, argv);
|
||||||
if (rval >= 0) /* -1 == connected and cd-ed */
|
if (rval >= 0) /* -1 == connected and cd-ed */
|
||||||
exit(rval);
|
exit(rval);
|
||||||
@ -487,6 +503,9 @@ main(int argc, char *argv[])
|
|||||||
retry_connect = 0; /* connected, stop hiding msgs */
|
retry_connect = 0; /* connected, stop hiding msgs */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isupload)
|
||||||
|
usage();
|
||||||
|
|
||||||
#ifndef NO_EDITCOMPLETE
|
#ifndef NO_EDITCOMPLETE
|
||||||
controlediting();
|
controlediting();
|
||||||
#endif /* !NO_EDITCOMPLETE */
|
#endif /* !NO_EDITCOMPLETE */
|
||||||
@ -952,9 +971,10 @@ void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"usage: %s [-AadefginpRtvV] [-o outfile] [-P port] [-r retry] [-T dir,max[,inc]\n"
|
"usage: %s [-AadefginpRtvV] [-o outfile] [-P port] [-r retry]\n"
|
||||||
" [[user@]host [port]] [host:path[/]] [file:///file]\n"
|
" [-T dir,max[,inc][[user@]host [port]]] [host:path[/]]\n"
|
||||||
" [ftp://[user[:pass]@]host[:port]/path[/]]\n"
|
" [file:///file] [ftp://[user[:pass]@]host[:port]/path[/]]\n"
|
||||||
" [http://[user[:pass]@]host[:port]/path] [...]\n", __progname);
|
" [http://[user[:pass]@]host[:port]/path] [...]\n"
|
||||||
|
" %s -u url file [...]\n", __progname, __progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: version.h,v 1.9 2000/05/28 07:53:31 lukem Exp $ */
|
/* $NetBSD: version.h,v 1.10 2000/05/31 14:23:59 lukem Exp $ */
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -40,5 +40,5 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FTP_VERSION
|
#ifndef FTP_VERSION
|
||||||
#define FTP_VERSION "20000528"
|
#define FTP_VERSION "20000601"
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user