1998-08-03 05:49:25 +04:00
|
|
|
/* $NetBSD: fetch.c,v 1.27 1998/08/03 01:49:25 lukem Exp $ */
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
/*-
|
1998-07-26 16:58:16 +04:00
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1997-01-19 17:19:02 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason Thorpe and Luke Mewburn.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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
|
1997-08-18 14:20:13 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1997-01-19 17:19:02 +03:00
|
|
|
* 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 SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-20 13:45:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#ifndef lint
|
1998-08-03 05:49:25 +04:00
|
|
|
__RCSID("$NetBSD: fetch.c,v 1.27 1998/08/03 01:49:25 lukem Exp $");
|
1997-01-19 17:19:02 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FTP User Program -- Command line file retrieval
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
#include <arpa/ftp.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
1998-06-04 12:28:35 +04:00
|
|
|
#include <errno.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <fcntl.h>
|
1997-03-13 09:23:11 +03:00
|
|
|
#include <signal.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
1998-07-22 20:06:27 +04:00
|
|
|
#include <util.h>
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
#include "ftp_var.h"
|
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
typedef enum {
|
|
|
|
UNKNOWN_URL_T=-1,
|
|
|
|
HTTP_URL_T,
|
|
|
|
FTP_URL_T,
|
|
|
|
FILE_URL_T
|
|
|
|
} url_t;
|
|
|
|
|
|
|
|
static int parse_url __P((const char *, const char *, url_t *, char **,
|
|
|
|
char **, char **, in_port_t *, char **));
|
1998-06-04 12:28:35 +04:00
|
|
|
static int url_get __P((const char *, const char *, const char *));
|
1997-07-20 13:45:35 +04:00
|
|
|
void aborthttp __P((int));
|
|
|
|
|
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
#define ABOUT_URL "about:" /* propaganda */
|
|
|
|
#define FILE_URL "file://" /* file URL prefix */
|
1997-01-19 17:19:02 +03:00
|
|
|
#define FTP_URL "ftp://" /* ftp URL prefix */
|
|
|
|
#define HTTP_URL "http://" /* http URL prefix */
|
1997-04-05 07:27:32 +04:00
|
|
|
#define FTP_PROXY "ftp_proxy" /* env var with ftp proxy location */
|
1997-01-19 17:19:02 +03:00
|
|
|
#define HTTP_PROXY "http_proxy" /* env var with http proxy location */
|
1998-08-03 05:49:25 +04:00
|
|
|
#define NO_PROXY "no_proxy" /* env var with list of non-proxied
|
|
|
|
* hosts, comma or space separated */
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0'))
|
1998-08-03 05:49:25 +04:00
|
|
|
#define FREEPTR(x) if ((x) != NULL) { free(x); (x) = NULL; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse URL of form:
|
|
|
|
* <type>://[<user>[:<password>@]]<host>[:<port>]/<url-path>
|
|
|
|
* Returns -1 if a parse error occurred, otherwise 0.
|
|
|
|
* Sets type to url_t, each of the given char ** pointers to a
|
|
|
|
* malloc(3)ed strings of the relevant section, and port to
|
|
|
|
* 0 if not given, or the number given.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
parse_url(url, desc, type, user, pass, host, port, path)
|
|
|
|
const char *url;
|
|
|
|
const char *desc;
|
|
|
|
url_t *type;
|
|
|
|
char **user;
|
|
|
|
char **pass;
|
|
|
|
char **host;
|
|
|
|
in_port_t *port;
|
|
|
|
char **path;
|
|
|
|
{
|
|
|
|
char *cp, *ep, *thost;
|
|
|
|
|
|
|
|
if (url == NULL || desc == NULL || type == NULL || user == NULL
|
|
|
|
|| pass == NULL || host == NULL || port == NULL || path == NULL)
|
|
|
|
errx(1, "parse_url: invoked with NULL argument!");
|
|
|
|
|
|
|
|
*type = UNKNOWN_URL_T;
|
|
|
|
*user = *pass = *host = *path = NULL;
|
|
|
|
*port = 0;
|
|
|
|
|
|
|
|
if (strncasecmp(url, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
|
|
|
|
url += sizeof(HTTP_URL) - 1;
|
|
|
|
*type = HTTP_URL_T;
|
|
|
|
} else if (strncasecmp(url, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
|
|
|
|
url += sizeof(FTP_URL) - 1;
|
|
|
|
*type = FTP_URL_T;
|
|
|
|
} else if (strncasecmp(url, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
|
|
|
|
url += sizeof(FILE_URL) - 1;
|
|
|
|
*type = FILE_URL_T;
|
|
|
|
} else {
|
|
|
|
warnx("Invalid %s `%s'", desc, url);
|
|
|
|
cleanup_parse_url:
|
|
|
|
FREEPTR(*user);
|
|
|
|
FREEPTR(*pass);
|
|
|
|
FREEPTR(*host);
|
|
|
|
FREEPTR(*path);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*url == '\0')
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* find [user[:pass]@]host[:port] */
|
|
|
|
ep = strchr(url, '/');
|
|
|
|
if (ep == NULL)
|
|
|
|
thost = xstrdup(url);
|
|
|
|
else {
|
|
|
|
size_t len = ep - url;
|
|
|
|
thost = (char *)xmalloc(len + 1);
|
|
|
|
strncpy(thost, url, len);
|
|
|
|
thost[len] = '\0';
|
|
|
|
*path = xstrdup(ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = strchr(thost, '@');
|
|
|
|
if (cp != NULL) {
|
|
|
|
*user = thost;
|
|
|
|
*cp = '\0';
|
|
|
|
*host = xstrdup(cp + 1);
|
|
|
|
cp = strchr(*user, ':');
|
|
|
|
if (cp != NULL) {
|
|
|
|
*cp = '\0';
|
|
|
|
*pass = xstrdup(cp + 1);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
*host = thost;
|
|
|
|
|
|
|
|
/* look for [:port] */
|
|
|
|
cp = strrchr(*host, ':');
|
|
|
|
if (cp != NULL) {
|
|
|
|
long nport;
|
|
|
|
|
|
|
|
*cp = '\0';
|
|
|
|
nport = strtol(cp + 1, &ep, 10);
|
|
|
|
if (nport < 1 || nport > MAX_IN_PORT_T || *ep != '\0') {
|
|
|
|
warnx("Invalid port `%s' in %s `%s'", cp, desc, line);
|
|
|
|
goto cleanup_parse_url;
|
|
|
|
}
|
|
|
|
*port = htons((in_port_t)nport);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
fprintf(ttyout,
|
|
|
|
"parse_url: user `%s', pass `%s', host %s:%d, path `%s'\n",
|
|
|
|
*user ? *user : "", *pass ? *pass : "", *host ? *host : "",
|
|
|
|
ntohs(*port), *path ? *path : "");
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
jmp_buf httpabort;
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/*
|
1997-04-05 07:27:32 +04:00
|
|
|
* Retrieve URL, via the proxy in $proxyvar if necessary.
|
1997-01-19 17:19:02 +03:00
|
|
|
* Modifies the string argument given.
|
|
|
|
* Returns -1 on failure, 0 on success
|
|
|
|
*/
|
1997-07-20 13:45:35 +04:00
|
|
|
static int
|
1998-08-03 05:49:25 +04:00
|
|
|
url_get(url, proxyenv, outfile)
|
|
|
|
const char *url;
|
1997-05-23 22:42:36 +04:00
|
|
|
const char *proxyenv;
|
1998-06-04 12:28:35 +04:00
|
|
|
const char *outfile;
|
1997-01-19 17:19:02 +03:00
|
|
|
{
|
|
|
|
struct sockaddr_in sin;
|
1998-08-03 05:49:25 +04:00
|
|
|
int isredirected, isproxy;
|
1997-07-20 13:45:35 +04:00
|
|
|
volatile int s;
|
1997-07-20 16:49:26 +04:00
|
|
|
size_t len;
|
1998-08-03 05:49:25 +04:00
|
|
|
char *cp, *ep;
|
1997-07-20 13:45:35 +04:00
|
|
|
const char *savefile;
|
1998-08-03 05:49:25 +04:00
|
|
|
char *buf;
|
1998-06-04 12:28:35 +04:00
|
|
|
volatile sig_t oldintr, oldintp;
|
1997-01-19 17:19:02 +03:00
|
|
|
off_t hashbytes;
|
1998-06-04 12:28:35 +04:00
|
|
|
struct hostent *hp = NULL;
|
|
|
|
int (*closefunc) __P((FILE *));
|
1998-07-22 20:06:27 +04:00
|
|
|
FILE *fin, *fout;
|
|
|
|
int retval;
|
1998-07-26 16:58:16 +04:00
|
|
|
time_t mtime;
|
1998-08-03 05:49:25 +04:00
|
|
|
url_t urltype;
|
|
|
|
char *user, *pass, *host;
|
|
|
|
in_port_t port;
|
|
|
|
char *path;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
closefunc = NULL;
|
1998-07-22 20:06:27 +04:00
|
|
|
fin = fout = NULL;
|
1997-01-19 17:19:02 +03:00
|
|
|
s = -1;
|
1998-08-03 05:49:25 +04:00
|
|
|
buf = NULL;
|
|
|
|
isredirected = isproxy = 0;
|
1998-07-22 20:06:27 +04:00
|
|
|
retval = -1;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
#ifdef __GNUC__ /* shut up gcc warnings */
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)&closefunc;
|
1998-07-22 20:06:27 +04:00
|
|
|
(void)&fin;
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)&fout;
|
1998-07-22 20:06:27 +04:00
|
|
|
(void)&buf;
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)&savefile;
|
1998-07-22 20:06:27 +04:00
|
|
|
(void)&retval;
|
1997-07-20 13:45:35 +04:00
|
|
|
#endif
|
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
if (parse_url(url, "URL", &urltype, &user, &pass, &host, &port, &path)
|
|
|
|
== -1)
|
|
|
|
goto cleanup_url_get;
|
|
|
|
if (port == 0)
|
|
|
|
port = httpport;
|
1997-04-05 07:27:32 +04:00
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
if (urltype == FILE_URL_T && ! EMPTYSTRING(host)
|
|
|
|
&& strcasecmp(host, "localhost") != 0) {
|
|
|
|
warnx("No support for non local file URL `%s'", url);
|
1998-07-26 16:58:16 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
1998-08-03 05:49:25 +04:00
|
|
|
|
1997-05-23 22:42:36 +04:00
|
|
|
if (EMPTYSTRING(path)) {
|
1998-07-26 16:58:16 +04:00
|
|
|
if (urltype == FTP_URL_T)
|
1997-06-29 10:34:50 +04:00
|
|
|
goto noftpautologin;
|
1998-08-03 05:49:25 +04:00
|
|
|
if (urltype != HTTP_URL_T || outfile == NULL) {
|
|
|
|
warnx("Invalid URL (no file after host) `%s'", url);
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
1997-05-23 22:42:36 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
if (outfile)
|
|
|
|
savefile = outfile;
|
|
|
|
else {
|
|
|
|
savefile = strrchr(path, '/'); /* find savefile */
|
|
|
|
if (savefile != NULL)
|
|
|
|
savefile++;
|
|
|
|
else
|
|
|
|
savefile = path;
|
|
|
|
}
|
1997-05-23 22:42:36 +04:00
|
|
|
if (EMPTYSTRING(savefile)) {
|
1998-07-26 16:58:16 +04:00
|
|
|
if (urltype == FTP_URL_T)
|
1997-06-29 10:34:50 +04:00
|
|
|
goto noftpautologin;
|
1998-08-03 05:49:25 +04:00
|
|
|
warnx("Invalid URL (no file after directory) `%s'", url);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-05-23 22:42:36 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
filesize = -1;
|
|
|
|
mtime = -1;
|
|
|
|
if (urltype == FILE_URL_T) { /* file:// URLs */
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
direction = "copied";
|
|
|
|
fin = fopen(path, "r");
|
|
|
|
if (fin == NULL) {
|
1998-08-03 05:49:25 +04:00
|
|
|
warn("Cannot open file `%s'", path);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
1998-07-26 16:58:16 +04:00
|
|
|
if (fstat(fileno(fin), &sb) == 0) {
|
|
|
|
mtime = sb.st_mtime;
|
|
|
|
filesize = sb.st_size;
|
|
|
|
}
|
|
|
|
fprintf(ttyout, "Copying %s\n", path);
|
|
|
|
} else { /* ftp:// or http:// URLs */
|
|
|
|
direction = "retrieved";
|
|
|
|
if (proxyenv != NULL) { /* use proxy */
|
1998-08-03 05:49:25 +04:00
|
|
|
url_t purltype;
|
|
|
|
char *puser, *ppass, *phost;
|
|
|
|
in_port_t pport;
|
|
|
|
char *ppath;
|
|
|
|
char *no_proxy;
|
|
|
|
|
|
|
|
isproxy = 1;
|
|
|
|
|
|
|
|
/* check URL against list of no_proxied sites */
|
|
|
|
no_proxy = getenv(NO_PROXY);
|
|
|
|
if (no_proxy != NULL) {
|
|
|
|
char *np, *np_copy;
|
|
|
|
long np_port;
|
|
|
|
size_t hlen, plen;
|
|
|
|
|
|
|
|
np_copy = xstrdup(no_proxy);
|
|
|
|
hlen = strlen(host);
|
|
|
|
while ((cp = strsep(&np_copy, " ,")) != NULL) {
|
|
|
|
if (*cp == '\0')
|
|
|
|
continue;
|
|
|
|
if ((np = strchr(cp, ':')) != NULL) {
|
|
|
|
*np = '\0';
|
|
|
|
np_port =
|
|
|
|
strtol(np + 1, &ep, 10);
|
|
|
|
if (*ep != '\0')
|
|
|
|
continue;
|
|
|
|
if (port !=
|
|
|
|
htons((in_port_t)np_port))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
plen = strlen(cp);
|
|
|
|
if (strncasecmp(host + hlen - plen,
|
|
|
|
cp, plen) == 0) {
|
|
|
|
isproxy = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FREEPTR(np_copy);
|
1998-07-26 16:58:16 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
if (isproxy) {
|
|
|
|
if (parse_url(proxyenv, "proxy URL", &purltype,
|
|
|
|
&puser, &ppass, &phost, &pport, &ppath)
|
|
|
|
== -1)
|
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
if ((purltype != HTTP_URL_T
|
|
|
|
&& purltype != FTP_URL_T) ||
|
|
|
|
EMPTYSTRING(phost) ||
|
|
|
|
(! EMPTYSTRING(ppath)
|
|
|
|
&& strcmp(ppath, "/") != 0)) {
|
|
|
|
warnx("Malformed proxy URL `%s'",
|
|
|
|
proxyenv);
|
|
|
|
FREEPTR(puser);
|
|
|
|
FREEPTR(ppass);
|
|
|
|
FREEPTR(phost);
|
|
|
|
FREEPTR(ppath);
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
|
|
|
|
FREEPTR(user);
|
|
|
|
user = puser;
|
|
|
|
FREEPTR(pass);
|
|
|
|
pass = ppass;
|
|
|
|
FREEPTR(host);
|
|
|
|
host = phost;
|
|
|
|
if (pport == 0)
|
|
|
|
port = httpport;
|
|
|
|
else
|
|
|
|
port = pport;
|
|
|
|
FREEPTR(path);
|
|
|
|
FREEPTR(ppath);
|
|
|
|
path = xstrdup(url);
|
|
|
|
}
|
|
|
|
} /* proxyenv != NULL */
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
if (isdigit((unsigned char)host[0])) {
|
|
|
|
if (inet_aton(host, &sin.sin_addr) == 0) {
|
1998-08-03 05:49:25 +04:00
|
|
|
warnx("Invalid IP address `%s'", host);
|
1998-07-26 16:58:16 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hp = gethostbyname(host);
|
|
|
|
if (hp == NULL) {
|
|
|
|
warnx("%s: %s", host, hstrerror(h_errno));
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
if (hp->h_addrtype != AF_INET) {
|
1998-08-03 05:49:25 +04:00
|
|
|
warnx("`%s': not an Internet address?", host);
|
1998-07-26 16:58:16 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
if (port == 0)
|
1998-07-26 16:58:16 +04:00
|
|
|
port = httpport;
|
|
|
|
sin.sin_port = port;
|
|
|
|
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (s == -1) {
|
|
|
|
warn("Can't create socket");
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
while (xconnect(s, (struct sockaddr *)&sin,
|
|
|
|
sizeof(sin)) == -1) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
|
|
|
if (hp && hp->h_addr_list[1]) {
|
|
|
|
int oerrno = errno;
|
|
|
|
char *ia;
|
|
|
|
|
|
|
|
ia = inet_ntoa(sin.sin_addr);
|
|
|
|
errno = oerrno;
|
1998-08-03 05:49:25 +04:00
|
|
|
warn("Connect to address `%s'", ia);
|
1998-07-26 16:58:16 +04:00
|
|
|
hp->h_addr_list++;
|
|
|
|
memcpy(&sin.sin_addr, hp->h_addr_list[0],
|
|
|
|
(size_t)hp->h_length);
|
|
|
|
fprintf(ttyout, "Trying %s...\n",
|
|
|
|
inet_ntoa(sin.sin_addr));
|
|
|
|
(void)close(s);
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
warn("Can't create socket");
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
continue;
|
1998-06-04 12:28:35 +04:00
|
|
|
}
|
1998-08-03 05:49:25 +04:00
|
|
|
warn("Can't connect to `%s'", host);
|
1998-07-26 16:58:16 +04:00
|
|
|
goto cleanup_url_get;
|
1998-06-04 12:28:35 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
fin = fdopen(s, "r+");
|
|
|
|
/*
|
1998-08-03 05:49:25 +04:00
|
|
|
* Construct and send the request.
|
|
|
|
* Proxy requests don't want leading /.
|
1998-07-26 16:58:16 +04:00
|
|
|
*/
|
1998-08-03 05:49:25 +04:00
|
|
|
if (isproxy) {
|
1998-07-26 16:58:16 +04:00
|
|
|
fprintf(ttyout, "Requesting %s\n (via %s)\n",
|
1998-08-03 05:49:25 +04:00
|
|
|
url, proxyenv);
|
1998-07-26 16:58:16 +04:00
|
|
|
fprintf(fin, "GET %s HTTP/1.0\r\n\r\n", path);
|
1998-08-03 05:49:25 +04:00
|
|
|
} else {
|
|
|
|
fprintf(ttyout, "Requesting %s\n", url);
|
|
|
|
fprintf(fin, "GET %s HTTP/1.1\r\n", path);
|
|
|
|
fprintf(fin, "Host: %s\r\n", host);
|
|
|
|
fprintf(fin, "Connection: close\r\n\r\n");
|
1998-07-26 16:58:16 +04:00
|
|
|
}
|
|
|
|
if (fflush(fin) == EOF) {
|
|
|
|
warn("Writing HTTP request");
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
/* Read the response */
|
1998-07-22 20:06:27 +04:00
|
|
|
if ((buf = fparseln(fin, &len, NULL, "\0\0\0", 0)) == NULL) {
|
|
|
|
warn("Receiving HTTP reply");
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
while (len > 0 && (buf[len-1] == '\r' || buf[len-1] == '\n'))
|
|
|
|
buf[--len] = '\0';
|
|
|
|
if (debug)
|
1998-08-03 05:49:25 +04:00
|
|
|
fprintf(ttyout, "received `%s'\n", buf);
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
cp = strchr(buf, ' ');
|
|
|
|
if (cp == NULL)
|
|
|
|
goto improper;
|
|
|
|
else
|
|
|
|
cp++;
|
|
|
|
if (strncmp(cp, "301", 3) == 0 || strncmp(cp, "302", 3) == 0) {
|
|
|
|
isredirected++;
|
|
|
|
} else if (strncmp(cp, "200", 3)) {
|
1998-08-03 05:49:25 +04:00
|
|
|
warnx("Error retrieving file `%s'", cp);
|
1998-07-26 16:58:16 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the rest of the header. */
|
1998-08-03 05:49:25 +04:00
|
|
|
FREEPTR(buf);
|
1998-07-26 16:58:16 +04:00
|
|
|
while (1) {
|
|
|
|
if ((buf = fparseln(fin, &len, NULL, "\0\0\0", 0))
|
|
|
|
== NULL) {
|
|
|
|
warn("Receiving HTTP reply");
|
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
while (len > 0 &&
|
|
|
|
(buf[len-1] == '\r' || buf[len-1] == '\n'))
|
|
|
|
buf[--len] = '\0';
|
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
if (debug)
|
1998-08-03 05:49:25 +04:00
|
|
|
fprintf(ttyout, "received `%s'\n", buf);
|
1998-07-26 16:58:16 +04:00
|
|
|
|
|
|
|
/* Look for some headers */
|
|
|
|
cp = buf;
|
1997-01-19 17:19:02 +03:00
|
|
|
#define CONTENTLEN "Content-Length: "
|
1998-07-26 16:58:16 +04:00
|
|
|
if (strncasecmp(cp, CONTENTLEN,
|
|
|
|
sizeof(CONTENTLEN) - 1) == 0) {
|
|
|
|
cp += sizeof(CONTENTLEN) - 1;
|
|
|
|
filesize = strtol(cp, &ep, 10);
|
|
|
|
if (filesize < 1 || *ep != '\0')
|
|
|
|
goto improper;
|
|
|
|
if (debug)
|
|
|
|
fprintf(ttyout,
|
|
|
|
#ifndef NO_QUAD
|
|
|
|
"parsed length as: %qd\n",
|
|
|
|
(long long)filesize);
|
|
|
|
#else
|
|
|
|
"parsed length as: %ld\n",
|
|
|
|
(long)filesize);
|
|
|
|
#endif
|
|
|
|
#define LASTMOD "Last-Modified: "
|
|
|
|
} else if (strncasecmp(cp, LASTMOD,
|
|
|
|
sizeof(LASTMOD) - 1) == 0) {
|
|
|
|
struct tm parsed;
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
cp += sizeof(LASTMOD) - 1;
|
|
|
|
/* RFC 1123 */
|
|
|
|
if ((t = strptime(cp,
|
|
|
|
"%a, %d %b %Y %H:%M:%S GMT",
|
|
|
|
&parsed))
|
|
|
|
/* RFC 850 */
|
|
|
|
|| (t = strptime(cp,
|
|
|
|
"%a, %d-%b-%y %H:%M:%S GMT",
|
|
|
|
&parsed))
|
|
|
|
/* asctime */
|
|
|
|
|| (t = strptime(cp,
|
|
|
|
"%a, %b %d %H:%M:%S %Y",
|
|
|
|
&parsed))) {
|
|
|
|
if (*t == '\0')
|
|
|
|
mtime = mktime(&parsed);
|
|
|
|
if (debug && mtime != -1)
|
|
|
|
fprintf(ttyout,
|
|
|
|
"parsed date as: %s",
|
|
|
|
ctime(&mtime));
|
|
|
|
}
|
1998-07-22 20:06:27 +04:00
|
|
|
#define LOCATION "Location: "
|
1998-07-26 16:58:16 +04:00
|
|
|
} else if (isredirected &&
|
|
|
|
strncasecmp(cp, LOCATION,
|
|
|
|
sizeof(LOCATION) - 1) == 0) {
|
|
|
|
cp += sizeof(LOCATION) - 1;
|
|
|
|
if (debug)
|
|
|
|
fprintf(ttyout,
|
|
|
|
"parsed location as: %s\n", cp);
|
|
|
|
if (verbose)
|
|
|
|
fprintf(ttyout,
|
|
|
|
"Redirected to %s\n", cp);
|
|
|
|
retval = url_get(cp, proxyenv, outfile);
|
1998-08-03 05:49:25 +04:00
|
|
|
goto cleanup_url_get;
|
1998-07-26 16:58:16 +04:00
|
|
|
}
|
1998-07-22 20:06:27 +04:00
|
|
|
}
|
1998-08-03 05:49:25 +04:00
|
|
|
FREEPTR(buf);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
oldintr = oldintp = NULL;
|
|
|
|
|
|
|
|
/* Open the output file. */
|
|
|
|
if (strcmp(savefile, "-") == 0) {
|
|
|
|
fout = stdout;
|
|
|
|
} else if (*savefile == '|') {
|
|
|
|
oldintp = signal(SIGPIPE, SIG_IGN);
|
|
|
|
fout = popen(savefile + 1, "w");
|
|
|
|
if (fout == NULL) {
|
1998-08-03 05:49:25 +04:00
|
|
|
warn("Can't run `%s'", savefile + 1);
|
1998-06-04 12:28:35 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
closefunc = pclose;
|
|
|
|
} else {
|
|
|
|
fout = fopen(savefile, "w");
|
|
|
|
if (fout == NULL) {
|
1998-08-03 05:49:25 +04:00
|
|
|
warn("Can't open `%s'", savefile);
|
1998-06-04 12:28:35 +04:00
|
|
|
goto cleanup_url_get;
|
|
|
|
}
|
|
|
|
closefunc = fclose;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
/* Trap signals */
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
if (setjmp(httpabort)) {
|
|
|
|
if (oldintr)
|
1997-03-13 09:23:11 +03:00
|
|
|
(void)signal(SIGINT, oldintr);
|
1998-06-04 12:28:35 +04:00
|
|
|
if (oldintp)
|
|
|
|
(void)signal(SIGPIPE, oldintp);
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
}
|
|
|
|
oldintr = signal(SIGINT, aborthttp);
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
bytes = 0;
|
|
|
|
hashbytes = mark;
|
|
|
|
progressmeter(-1);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
|
1998-07-22 20:06:27 +04:00
|
|
|
/* Finally, suck down the file. */
|
1998-08-03 05:49:25 +04:00
|
|
|
buf = xmalloc(BUFSIZ);
|
1998-07-22 20:06:27 +04:00
|
|
|
while ((len = fread(buf, sizeof(char), BUFSIZ, fin)) > 0) {
|
1997-01-19 17:19:02 +03:00
|
|
|
bytes += len;
|
1998-07-26 16:58:16 +04:00
|
|
|
if (fwrite(buf, sizeof(char), len, fout) != len) {
|
1998-08-03 05:49:25 +04:00
|
|
|
warn("Writing `%s'", savefile);
|
1998-07-26 16:58:16 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
if (hash && !progress) {
|
|
|
|
while (bytes >= hashbytes) {
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)putc('#', ttyout);
|
1997-01-19 17:19:02 +03:00
|
|
|
hashbytes += mark;
|
|
|
|
}
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)fflush(ttyout);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hash && !progress && bytes > 0) {
|
|
|
|
if (bytes < mark)
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)putc('#', ttyout);
|
|
|
|
(void)putc('\n', ttyout);
|
|
|
|
(void)fflush(ttyout);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
1998-07-26 16:58:16 +04:00
|
|
|
if (ferror(fin)) {
|
|
|
|
warn("Reading file");
|
1997-04-05 07:27:32 +04:00
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
progressmeter(1);
|
1998-07-26 16:58:16 +04:00
|
|
|
(void)fflush(fout);
|
1997-03-13 09:23:11 +03:00
|
|
|
(void)signal(SIGINT, oldintr);
|
1998-06-04 12:28:35 +04:00
|
|
|
if (oldintp)
|
|
|
|
(void)signal(SIGPIPE, oldintp);
|
1998-07-26 16:58:16 +04:00
|
|
|
if (closefunc == fclose && mtime != -1) {
|
|
|
|
struct timeval tval[2];
|
|
|
|
|
|
|
|
(void)gettimeofday(&tval[0], NULL);
|
|
|
|
tval[1].tv_sec = mtime;
|
|
|
|
tval[1].tv_usec = 0;
|
|
|
|
if (futimes(fileno(fout), tval) == -1) {
|
|
|
|
fprintf(ttyout,
|
|
|
|
"Can't change modification time to %s",
|
|
|
|
asctime(localtime(&mtime)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bytes > 0)
|
|
|
|
ptransfer(0);
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-22 20:06:27 +04:00
|
|
|
retval = 0;
|
|
|
|
goto cleanup_url_get;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1997-06-29 10:34:50 +04:00
|
|
|
noftpautologin:
|
|
|
|
warnx(
|
|
|
|
"Auto-login using ftp URLs isn't supported when using $ftp_proxy");
|
|
|
|
goto cleanup_url_get;
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
improper:
|
1998-08-03 05:49:25 +04:00
|
|
|
warnx("Improper response from `%s'", host);
|
1997-06-29 10:34:50 +04:00
|
|
|
|
1997-04-05 07:27:32 +04:00
|
|
|
cleanup_url_get:
|
1998-07-10 08:39:03 +04:00
|
|
|
resetsockbufsize();
|
1998-07-22 20:06:27 +04:00
|
|
|
if (fin != NULL)
|
|
|
|
fclose(fin);
|
|
|
|
else if (s != -1)
|
1997-01-19 17:19:02 +03:00
|
|
|
close(s);
|
1998-06-04 12:28:35 +04:00
|
|
|
if (closefunc != NULL && fout != NULL)
|
|
|
|
(*closefunc)(fout);
|
1998-08-03 05:49:25 +04:00
|
|
|
FREEPTR(user);
|
|
|
|
FREEPTR(pass);
|
|
|
|
FREEPTR(host);
|
|
|
|
FREEPTR(path);
|
|
|
|
FREEPTR(buf);
|
1998-07-22 20:06:27 +04:00
|
|
|
return (retval);
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
/*
|
|
|
|
* Abort a http retrieval
|
|
|
|
*/
|
|
|
|
void
|
1997-03-13 09:23:11 +03:00
|
|
|
aborthttp(notused)
|
|
|
|
int notused;
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
alarmtimer(0);
|
1998-07-22 20:06:27 +04:00
|
|
|
fputs("\nHTTP fetch aborted.\n", ttyout);
|
1998-06-04 12:28:35 +04:00
|
|
|
(void)fflush(ttyout);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
longjmp(httpabort, 1);
|
|
|
|
}
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/*
|
|
|
|
* Retrieve multiple files from the command line, transferring
|
1998-07-26 16:58:16 +04:00
|
|
|
* URLs of the form "host:path", "ftp://host/path" using the
|
|
|
|
* ftp protocol, URLs of the form "http://host/path" using the
|
|
|
|
* http protocol, and URLs of the form "file:///" by simple
|
|
|
|
* copying.
|
1997-03-13 09:23:11 +03:00
|
|
|
* If path has a trailing "/", then return (-1);
|
1997-01-19 17:19:02 +03:00
|
|
|
* the path will be cd-ed into and the connection remains open,
|
|
|
|
* and the function will return -1 (to indicate the connection
|
|
|
|
* is alive).
|
|
|
|
* If an error occurs the return value will be the offset+1 in
|
|
|
|
* argv[] of the file that caused a problem (i.e, argv[x]
|
|
|
|
* returns x+1)
|
|
|
|
* Otherwise, 0 is returned if all files retrieved successfully.
|
|
|
|
*/
|
|
|
|
int
|
1998-06-04 12:28:35 +04:00
|
|
|
auto_fetch(argc, argv, outfile)
|
1997-01-19 17:19:02 +03:00
|
|
|
int argc;
|
|
|
|
char *argv[];
|
1998-06-04 12:28:35 +04:00
|
|
|
char *outfile;
|
1997-01-19 17:19:02 +03:00
|
|
|
{
|
|
|
|
static char lasthost[MAXHOSTNAMELEN];
|
1998-08-03 05:49:25 +04:00
|
|
|
char portnum[6]; /* large enough for "65535\0" */
|
1997-01-19 17:19:02 +03:00
|
|
|
char *xargv[5];
|
1998-08-03 05:49:25 +04:00
|
|
|
const char *line;
|
|
|
|
char *cp, *host, *path, *dir, *file;
|
1997-04-14 13:09:15 +04:00
|
|
|
char *user, *pass;
|
1998-08-03 05:49:25 +04:00
|
|
|
in_port_t port;
|
1997-04-05 07:27:32 +04:00
|
|
|
char *ftpproxy, *httpproxy;
|
1997-07-20 13:45:35 +04:00
|
|
|
int rval, xargc;
|
|
|
|
volatile int argpos;
|
1997-03-13 09:23:11 +03:00
|
|
|
int dirhasglob, filehasglob;
|
|
|
|
char rempath[MAXPATHLEN];
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-06-04 12:28:35 +04:00
|
|
|
#ifdef __GNUC__ /* to shut up gcc warnings */
|
|
|
|
(void)&outfile;
|
|
|
|
#endif
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
argpos = 0;
|
1997-01-19 17:19:02 +03:00
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
if (setjmp(toplevel)) {
|
|
|
|
if (connected)
|
|
|
|
disconnect(0, NULL);
|
1997-03-13 09:23:11 +03:00
|
|
|
return (argpos + 1);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
}
|
1997-03-13 09:23:11 +03:00
|
|
|
(void)signal(SIGINT, (sig_t)intr);
|
|
|
|
(void)signal(SIGPIPE, (sig_t)lostpeer);
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1997-04-05 07:27:32 +04:00
|
|
|
ftpproxy = getenv(FTP_PROXY);
|
|
|
|
httpproxy = getenv(HTTP_PROXY);
|
1998-08-03 05:49:25 +04:00
|
|
|
host = path = dir = file = user = pass = NULL;
|
1997-04-05 07:27:32 +04:00
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/*
|
|
|
|
* Loop through as long as there's files to fetch.
|
|
|
|
*/
|
1998-08-03 05:49:25 +04:00
|
|
|
for (rval = 0; (rval == 0) && (argpos < argc); argpos++) {
|
1997-01-19 17:19:02 +03:00
|
|
|
if (strchr(argv[argpos], ':') == NULL)
|
|
|
|
break;
|
1998-08-03 05:49:25 +04:00
|
|
|
host = path = dir = file = user = pass = NULL;
|
|
|
|
line = argv[argpos];
|
1997-01-19 17:19:02 +03:00
|
|
|
|
1998-07-26 16:58:16 +04:00
|
|
|
#ifndef SMALL
|
|
|
|
/*
|
|
|
|
* Check for about:*
|
|
|
|
*/
|
|
|
|
if (strncasecmp(line, ABOUT_URL, sizeof(ABOUT_URL) - 1) == 0) {
|
1998-08-03 05:49:25 +04:00
|
|
|
line += sizeof(ABOUT_URL) -1;
|
|
|
|
if (strcasecmp(line, "ftp") == 0) {
|
1998-07-26 16:58:16 +04:00
|
|
|
fprintf(ttyout, "%s\n%s\n",
|
1998-07-26 16:59:40 +04:00
|
|
|
"This version of ftp has been enhanced by Luke Mewburn <lukem@netbsd.org>.",
|
1998-07-26 16:58:16 +04:00
|
|
|
"Execute 'man ftp' for more details");
|
1998-08-03 05:49:25 +04:00
|
|
|
} else if (strcasecmp(line, "netbsd") == 0) {
|
1998-07-26 16:58:16 +04:00
|
|
|
fprintf(ttyout, "%s\n%s\n",
|
|
|
|
"NetBSD is a freely available and redistributable UNIX-like operating system.",
|
|
|
|
"For more information, see http://www.netbsd.org/index.html");
|
|
|
|
} else {
|
|
|
|
fprintf(ttyout,
|
1998-08-03 05:49:25 +04:00
|
|
|
"`%s' is an interesting topic.\n", line);
|
1998-07-26 16:58:16 +04:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* SMALL */
|
|
|
|
|
1997-01-19 17:19:02 +03:00
|
|
|
/*
|
1998-07-26 16:58:16 +04:00
|
|
|
* Check for file:// and http:// URLs.
|
1997-01-19 17:19:02 +03:00
|
|
|
*/
|
1998-07-26 16:58:16 +04:00
|
|
|
if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0 ||
|
|
|
|
strncasecmp(line, FILE_URL, sizeof(FILE_URL) - 1) == 0) {
|
1998-06-04 12:28:35 +04:00
|
|
|
if (url_get(line, httpproxy, outfile) == -1)
|
1997-01-19 17:19:02 +03:00
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-04-05 07:27:32 +04:00
|
|
|
* Try FTP URL-style arguments next. If ftpproxy is
|
|
|
|
* set, use url_get() instead of standard ftp.
|
|
|
|
* Finally, try host:file.
|
1997-01-19 17:19:02 +03:00
|
|
|
*/
|
1997-04-14 13:09:15 +04:00
|
|
|
if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
|
1998-08-03 05:49:25 +04:00
|
|
|
int urltype;
|
|
|
|
|
1997-04-05 07:27:32 +04:00
|
|
|
if (ftpproxy) {
|
1998-06-04 12:28:35 +04:00
|
|
|
if (url_get(line, ftpproxy, outfile) == -1)
|
1997-04-05 07:27:32 +04:00
|
|
|
rval = argpos + 1;
|
|
|
|
continue;
|
|
|
|
}
|
1998-08-03 05:49:25 +04:00
|
|
|
if ((parse_url(line, "URL", &urltype, &user, &pass,
|
|
|
|
&host, &port, &path) == -1) ||
|
|
|
|
(user != NULL && *user == '\0') ||
|
|
|
|
(pass != NULL && *pass == '\0') ||
|
|
|
|
EMPTYSTRING(host)) {
|
|
|
|
warnx("Invalid URL `%s'", argv[argpos]);
|
1997-04-14 13:09:15 +04:00
|
|
|
rval = argpos + 1;
|
1998-08-03 05:49:25 +04:00
|
|
|
break;
|
1997-04-14 13:09:15 +04:00
|
|
|
}
|
|
|
|
} else { /* classic style `host:file' */
|
1998-08-03 05:49:25 +04:00
|
|
|
host = xstrdup(line);
|
|
|
|
cp = strchr(host, ':');
|
|
|
|
if (cp != NULL) {
|
|
|
|
*cp = '\0';
|
|
|
|
path = xstrdup(cp + 1);
|
|
|
|
}
|
1997-04-14 13:09:15 +04:00
|
|
|
}
|
1997-01-19 17:19:02 +03:00
|
|
|
if (EMPTYSTRING(host)) {
|
|
|
|
rval = argpos + 1;
|
1998-08-03 05:49:25 +04:00
|
|
|
break;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-13 13:05:52 +04:00
|
|
|
* If dir is NULL, the file wasn't specified
|
1997-01-19 17:19:02 +03:00
|
|
|
* (URL looked something like ftp://host)
|
|
|
|
*/
|
1998-08-03 05:49:25 +04:00
|
|
|
dir = path;
|
1997-04-14 13:09:15 +04:00
|
|
|
if (dir != NULL)
|
|
|
|
*dir++ = '\0';
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the file and (if present) directory name.
|
|
|
|
*/
|
|
|
|
if (! EMPTYSTRING(dir)) {
|
1997-04-14 13:09:15 +04:00
|
|
|
cp = strrchr(dir, '/');
|
1997-01-19 17:19:02 +03:00
|
|
|
if (cp != NULL) {
|
|
|
|
*cp++ = '\0';
|
|
|
|
file = cp;
|
|
|
|
} else {
|
|
|
|
file = dir;
|
|
|
|
dir = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (debug)
|
1998-06-04 12:28:35 +04:00
|
|
|
fprintf(ttyout,
|
1998-08-03 05:49:25 +04:00
|
|
|
"auto_fetch: user `%s', pass `%s', host %s:%d, path, `%s', dir `%s', file `%s'\n",
|
|
|
|
user ? user : "", pass ? pass : "",
|
|
|
|
host ? host : "", ntohs(port), path ? path : "",
|
|
|
|
dir ? dir : "", file ? file : "");
|
1997-01-19 17:19:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the connection if we don't have one.
|
|
|
|
*/
|
1998-08-03 05:49:25 +04:00
|
|
|
if (strcasecmp(host, lasthost) != 0) {
|
1997-04-14 13:09:15 +04:00
|
|
|
int oautologin;
|
|
|
|
|
1997-03-16 17:24:14 +03:00
|
|
|
(void)strcpy(lasthost, host);
|
1997-01-19 17:19:02 +03:00
|
|
|
if (connected)
|
|
|
|
disconnect(0, NULL);
|
|
|
|
xargv[0] = __progname;
|
|
|
|
xargv[1] = host;
|
|
|
|
xargv[2] = NULL;
|
|
|
|
xargc = 2;
|
1998-08-03 05:49:25 +04:00
|
|
|
if (port) {
|
|
|
|
snprintf(portnum, sizeof(portnum),
|
|
|
|
"%d", (int)port);
|
1997-01-19 17:19:02 +03:00
|
|
|
xargv[2] = portnum;
|
|
|
|
xargv[3] = NULL;
|
|
|
|
xargc = 3;
|
|
|
|
}
|
1997-04-14 13:09:15 +04:00
|
|
|
oautologin = autologin;
|
|
|
|
if (user != NULL)
|
|
|
|
autologin = 0;
|
1997-01-19 17:19:02 +03:00
|
|
|
setpeer(xargc, xargv);
|
1997-04-14 13:09:15 +04:00
|
|
|
autologin = oautologin;
|
|
|
|
if ((connected == 0)
|
1998-07-22 20:06:27 +04:00
|
|
|
|| ((connected == 1) &&
|
|
|
|
!ftp_login(host, user, pass)) ) {
|
1997-04-14 13:09:15 +04:00
|
|
|
warnx("Can't connect or login to host `%s'",
|
|
|
|
host);
|
1997-01-19 17:19:02 +03:00
|
|
|
rval = argpos + 1;
|
1998-08-03 05:49:25 +04:00
|
|
|
break;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Always use binary transfers. */
|
|
|
|
setbinary(0, NULL);
|
|
|
|
}
|
1998-08-03 05:49:25 +04:00
|
|
|
/* cd back to `/' */
|
1997-04-14 13:09:15 +04:00
|
|
|
xargv[0] = "cd";
|
|
|
|
xargv[1] = "/";
|
|
|
|
xargv[2] = NULL;
|
|
|
|
cd(2, xargv);
|
|
|
|
if (! dirchange) {
|
|
|
|
rval = argpos + 1;
|
1998-08-03 05:49:25 +04:00
|
|
|
break;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
1997-03-13 09:23:11 +03:00
|
|
|
dirhasglob = filehasglob = 0;
|
|
|
|
if (doglob) {
|
|
|
|
if (! EMPTYSTRING(dir) &&
|
|
|
|
strpbrk(dir, "*?[]{}") != NULL)
|
|
|
|
dirhasglob = 1;
|
|
|
|
if (! EMPTYSTRING(file) &&
|
|
|
|
strpbrk(file, "*?[]{}") != NULL)
|
|
|
|
filehasglob = 1;
|
|
|
|
}
|
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
/* Change directories, if necessary. */
|
1997-03-13 09:23:11 +03:00
|
|
|
if (! EMPTYSTRING(dir) && !dirhasglob) {
|
1997-01-19 17:19:02 +03:00
|
|
|
xargv[0] = "cd";
|
|
|
|
xargv[1] = dir;
|
|
|
|
xargv[2] = NULL;
|
|
|
|
cd(2, xargv);
|
|
|
|
if (! dirchange) {
|
|
|
|
rval = argpos + 1;
|
1998-08-03 05:49:25 +04:00
|
|
|
break;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EMPTYSTRING(file)) {
|
|
|
|
rval = -1;
|
1998-08-03 05:49:25 +04:00
|
|
|
break;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
if (!verbose)
|
1998-06-04 12:28:35 +04:00
|
|
|
fprintf(ttyout, "Retrieving %s/%s\n", dir ? dir : "",
|
|
|
|
file);
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
|
1997-03-13 09:23:11 +03:00
|
|
|
if (dirhasglob) {
|
|
|
|
snprintf(rempath, sizeof(rempath), "%s/%s", dir, file);
|
|
|
|
file = rempath;
|
|
|
|
}
|
|
|
|
|
1998-08-03 05:49:25 +04:00
|
|
|
/* Fetch the file(s). */
|
1998-06-04 12:28:35 +04:00
|
|
|
xargc = 2;
|
1997-01-19 17:19:02 +03:00
|
|
|
xargv[0] = "get";
|
|
|
|
xargv[1] = file;
|
|
|
|
xargv[2] = NULL;
|
1997-03-13 09:23:11 +03:00
|
|
|
if (dirhasglob || filehasglob) {
|
|
|
|
int ointeractive;
|
|
|
|
|
|
|
|
ointeractive = interactive;
|
|
|
|
interactive = 0;
|
|
|
|
xargv[0] = "mget";
|
1998-06-04 12:28:35 +04:00
|
|
|
mget(xargc, xargv);
|
1997-03-16 17:24:14 +03:00
|
|
|
interactive = ointeractive;
|
1998-06-04 12:28:35 +04:00
|
|
|
} else {
|
|
|
|
if (outfile != NULL) {
|
|
|
|
xargv[2] = outfile;
|
|
|
|
xargv[3] = NULL;
|
|
|
|
xargc++;
|
|
|
|
}
|
|
|
|
get(xargc, xargv);
|
|
|
|
if (outfile != NULL && strcmp(outfile, "-") != 0
|
|
|
|
&& outfile[0] != '|')
|
|
|
|
outfile = NULL;
|
|
|
|
}
|
1997-03-13 09:23:11 +03:00
|
|
|
|
|
|
|
if ((code / 100) != COMPLETE)
|
[Yet Another Huge Ftp Commit - hopefully the last for a while,
barring any more little things people want added ...]
New features:
* progressmeter is now asynchronous, so "stalled" transfers can be
detected. "- stalled -" is displayed instead of the ETA in this case.
When the xfer resumes, the time that the xfer was stalled for is
factored out of the ETA. It is debatable whether this is better than
not factoring it out, but I like it this way (I.e, if it stalls for 8
seconds and the ETA was 30 seconds, when it resumes the ETA will still
be 30 seconds).
* verbosity can be disabled on the command line (-V), so that in auto-fetch
mode the only lines displayed will be a description of the file, and
the progress bar (if possible)
* if the screen is resized (and detected via the SIGWINCH signal), the
progress bar will rescale automatically.
Bugs fixed:
* progress bar will not use the last character on the line, as this can
cause problems on some terminals
* screen dimensions (via ioctl(TIOCWINSZ)) should use stdout not stdin
* progressmeter() used some vars before initialising them
* ^D will quit now. [fixes bin/3162]
* use hstrerror() to generate error message for host name lookup failure.
* use getcwd instead of getwd (it should have been OK, but why tempt fate?)
* auto-fetch transfers will always return a positive exit value upon failure
or interruption, relative to the file's position in argv[].
* remote completion of / will work, without putting a leading "///".
This is actually a bug in ftpd(1), where "NLST /" prefixes all names
with "//", but fixing every ftpd(1) is not an option...
1997-02-01 13:44:54 +03:00
|
|
|
rval = argpos + 1;
|
1997-01-19 17:19:02 +03:00
|
|
|
}
|
|
|
|
if (connected && rval != -1)
|
|
|
|
disconnect(0, NULL);
|
1998-08-03 05:49:25 +04:00
|
|
|
FREEPTR(host);
|
|
|
|
FREEPTR(path);
|
|
|
|
FREEPTR(user);
|
|
|
|
FREEPTR(pass);
|
1997-01-19 17:19:02 +03:00
|
|
|
return (rval);
|
|
|
|
}
|