Commit Graph

59 Commits

Author SHA1 Message Date
lukem e25749a582 [fear this; more ftp hacking from lukem :-]
features:
---------
* transfer rate throttling with the new `rate' command. syntax:
	rate direction [max [incr]]
  where direction is `all', `get' or `put'.
  if max is not supplied, the current settings are displayed.
  if max is supplied, then transfers in the given direction will
  be throttled to this value.
  if incr is supplied, the increment for the `on-the-fly' scaling
  will be set to that, otherwise `1024' is used.
  currently implemented for binary get, binary put, and url fetches.
  not yet supported for ascii get or put, or local file copies.
* on-the-fly scaling of the throttle based on signals:
    - SIGUSR1 raises the throttle rate by the increment for that direction
    - SIGUSR2 lowers the throttle rate by the increment for that direction
* -T dir,max[,incr] option to set rate from the command line
* `k', `m', `g' suffix support for bytecounts in the `hash', `rate',
  `rcvbuf' and `sndbuf' commands)

bug fixes and code mods:
------------------------
* fix up ftp_login() so that ruserpass() is always called, even for
  command-line url fetches.
* implement strsuftoi(), which parses a given number into a int with
  suffix support. replaces getsockbufsize()
* implement parserate(), which does the argv parsing for -T and rate
* save and restore errno in signal handlers (may not be necessary, but
  it doesn't hurt)

notes:
------
the rate command has had reasonable testing, but I'd like feedback
if it doesn't do the right thing, especially from people on slower
(i.e, modem) links.
I haven't tested the rate throttle against a http server which does
`transfer-encoding: chunked' because I couldn't find a server to
test against.
1999-06-29 10:43:16 +00:00
lukem 3ba4ce083e don't search for trailing `;type=' in a NULL path...
fixes [bin/7800] by Mason Loring Bliss <mason@acheron.middleboro.ma.us>
1999-06-27 01:17:19 +00:00
christos bf00d14ab4 include time.h explicitly, don't depend on other include side-effects 1999-06-24 14:48:35 +00:00
cgd d78b6bd31e split the "SMALL" #ifdefs into ones for NO_ABOUT, NO_EDITCOMPLETE, and
NO_PROGRESS.  -DSMALL still implies all of those.  progress meter support
isn't necessary for the smallest possible ftp client, but it adds very
little space and makes users' lives much better.  Therefore, it should
be enabled for installation media if at all possible.
1999-06-20 22:07:28 +00:00
lukem f7540e6f75 * fix gate mode to login as `user@realhost' rather than using PASSERVE;
the latter only seemed to work for TIS Gauntlet and not TIS fwtk.
  thanks to simonb@netbsd.org for testing this. fixes [bin/5556].
* if EOF (e.g, ^D) is entered at a username/password/account prompt which
  happens to use fgets(), exit the login rather than treating EOF as CR.
* don't use the comma operator where separate statements are valid
* always use snprintf to copy stuff into malloced buffers, just in case
  typos creep in and mean that the buffer ends up being overflowed
1999-06-02 02:03:57 +00:00
lukem 4494ebf448 parse http:// urls (and the $http_proxy variable) for [user:[pass]@]
elements, which are used for the initial authentication attempt (if
requested by the server).  in the case of $http_proxy, use the values
for proxy authentication.
1999-05-12 11:16:43 +00:00
lukem f55d4712e3 * make parsing of ftp:// urls more RFC 1738 compliant;
- the path is split on `/', and each directory is CWD-ed into separately.
      (from [standards/7484] by Alan Barrett <apb@iafrica.com>)
    - support a trailing `;type=X' suffix, where X is a,i, or d.  (d isn't
      implemented, but it is recognised)
    - the only non-compliant behaviour is that empty directories sections
      (e.g `//') aren't run as `CWD ' - as a lot of ftpds don't like that.
      Instead, treat this as a no-op.
* don't support globbing for ftp urls, since that's technically not
  RFC compliant.
* fix a couple of man-page nits
1999-04-28 13:35:40 +00:00
lukem bed9aad370 * implement -R; restart non-proxied command-line FTP xfers
* fix fetch_ftp() so that hcode parsing is not done for file:// urls
  (a } in the wrong place, and code at the wrong indent level...)
* change outfile to being a global (so it gets correctly reset)
* change parse_url to not remove leading '/' for non ftp urls.
  whilst this is not totally rfc1738 compliant, other code kinda
  assumes this is the case, and it doesn't hurt
1999-03-22 07:36:40 +00:00
christos 3853a6978b Add a few more variables that end up in registers in gcc-2.8.1 1999-03-15 08:52:17 +00:00
lukem 5a1118c5f9 * add url_decode() - `in-place' decode %xx escapes in a given url component
* parse_url()
-   only look for user[:pass] for an ftp url (per rfc1738)
-   strip leading /'s in an ftp url. (almost per rfc 1738)
* fetch_url()
-   decode a copy of the path and use that to build local filenames
-   send port in http Host: header (suggested by cgd@netbsd.org)
* fetch_ftp()
-   url_decode() the user, pass and path
-   fix splitting of path into dir & file (partially from [bin/7073])
-   don't bother caching the last host; it can cause problems when
    using ftp:// transfers, or when the user changes between xfers
* improve documentation of auto-fetched url arguments (especially regarding
  escape sequences in ftp:// urls)
* some whitespace & copyright updates

this should fix [bin/7073] William O Ferry <woferry@warp.wofme.com>,
as well as the metaissues raised in that PR.
1999-03-08 04:36:12 +00:00
lukem e2352fc342 only print "Requesting..." messages if (verbose) 1999-01-25 23:17:37 +00:00
lukem 0bd80459cb * -v enables verbose & progress, -V disables both
* set setvbuf(ttyout, NULL, _IOLBF, 0) and remove a bunch of fflush(ttyout).
* use fwrite() instead of write() for progressmeter (don't intermix stdio
  with non stdio ops)
1999-01-24 02:39:29 +00:00
lukem 0e87f1b53d support -f, which forces a cache flush for http xfers using either
`Pragma: no-cache' (http/1.0) or `Cache-Control: no-cache' (http/1.1)
1999-01-23 15:46:24 +00:00
lukem 6ae118efdb add missing braces (this is C not python...). fixes coredump on solaris 1999-01-05 00:31:20 +00:00
lukem 234fb36cc6 support http/1.1's `transfer-encoding: chunked' mode. [noted by hubertf & bad] 1999-01-01 13:26:31 +00:00
lukem 1f3ec47c0f * implement auth_url(); given a challenge, decode it, ask the user for
a response, and return the base64 encoded response. only the `Basic'
  scheme is supported.
* implement base64_enc(), which base64 encodes the given buffer
* add support for http response codes 401 "authorization required" and 407
  "proxy authorization required", using auth_url(). [requested by veego@]
1999-01-01 10:00:46 +00:00
lukem 974dee5975 use uname(3) to determine info to send in User-agent: header. (suggested by cgd) 1998-12-31 02:10:34 +00:00
lukem cc66a8544e * major code reorg; gut auto_fetch() and url_get() into a smaller auto_fetch(),
do_fetch() - which retrieves one file calling fetch_url() or fetch_ftp()
  as necessary.
* don't http redirect more than 5 times for a given url
* send `User-Agent: NetBSD-ftp/1.4' header in http requests. (suggested
  by Christoph Badura <bad@ora.de>)
* cleanup http return code parser, and add support for:
    - 300 `Multiple Choices' - but only if the server returns a
      preferred url in a Location: header because i'm *not* adding
      a html parser to provide the user with options.
    - 305 `Use Proxy [given in Location: header]'. (XXX: not tested)
* support http redirects to non-proxied ftp://urls. (bug discovered by
  Chris Demetriou <cgd@netbsd.org>)
* auto-login to an ftp site (using the FTP protocol) if an ftp://host/dir/
  style url is given and ftp_proxy is set. whilst this is less orthoganol
  with other ftp://host/file urls it's *much* more convenient.
1998-12-29 14:59:04 +00:00
lukem ee32f5a96b be saner about the method to determine which $proxy to use 1998-12-27 05:49:53 +00:00
explorer faade9c8e2 Send an Accept: */* header, since some sites require content negotiation.
Grr.
1998-11-22 06:52:32 +00:00
itohy 6d075e2860 Temporary fix of UTC -> time_t conversion:
1. changed to use timegm(3) on NetBSD and
2. supply alternative code for other Unix-like OSs
(NetBSD ftp shall be portable for some reasons :-).

This fix closes PR #6448.

NOTE: This should be fixed again if a portable UTC to time_t
conversion method is specified in some standards.
1998-11-18 07:24:25 +00:00
lukem fa954d84d1 * fix previous in a more portable manner (timegm() is not portable/standard).
use mktime(), and adjust to GMT as per code in util.c::remotemodtime()
1998-11-12 22:27:17 +00:00
itohy 638ec4fd83 HTTP uses UTC time, and changed to use timegm(3) instead of mktime(3)
for conversion of HTTP time.

XXX Unfortunately, timegm(3) is not portable (ex. SunOS 4 have, but 5 not).
1998-11-12 18:19:02 +00:00
lukem da0a823fb0 * hash & progress are mutually exclusive. [noted by mrg@netbsd.org]
* in autofetch mode, don't attempt to 'cd /' on first xfer (only on
  subsequent xfers), as some ftp daemons don't permit that.
  [noted by dbj@netbsd.org].
  XXX: code could be smarter (but a lot more complicated to boot); this
  works for now.
1998-10-08 14:45:26 +00:00
lukem 70b3ec2f32 fix handling of port on non-proxied auto-fetch ftp:// urls 1998-09-01 04:42:49 +00:00
lukem f0622bf9a4 some compilers bitch about int used when enum expected... 1998-08-08 11:23:46 +00:00
lukem 07a9ebee13 * fix skipping of leading / in dir, which may have resulted in
parsing junk memory (picked up whilst porting to solaris)
* remove superfluous var assignments
1998-08-08 04:40:50 +00:00
lukem 6a9c077701 pull in <sys/time.h> for utimes(), reset port to 0 in auto_fetch loop 1998-08-08 04:04:17 +00:00
lukem e4a646bf1c use utimes() instead of futimes() - the former is more portable 1998-08-08 03:33:20 +00:00
lukem edcec00949 technically, you need <sys/stat.h> for struct stat .... 1998-08-08 03:06:00 +00:00
lukem 69761d6f64 cleaner version of fvdl's previous fix, using xstrdup as well 1998-08-04 03:35:24 +00:00
fvdl 14f785118c Avoid using freed memory when using URLs and a proxy. 1998-08-03 19:10:29 +00:00
lukem 4a8ec5494d features:
* support $no_proxy, which is a comma or space separated list of
  host[:port] elements for which proxying is to be disabled.
  (asked for by cgd in [bin/5027])
* if $FTPANONPASS is defined, use that as the anon ftp password
  (instead of "`whoami`@")
* allow http URL's without a filename as long as an output file
  is specified.

other stuff:
* implement parse_url(), which breaks up a URL into its bits, and use.
* simplify url_get() and auto_fetch() to use parse_url() and to not
  modify the supplied URL or a copy of it.
* implement xmalloc() and xstrdup(); error-checked malloc()/strdup()
* add more consistency to messages, quoting strings in output as `%s'
1998-08-03 01:49:25 +00:00
lukem 5ae8291cc6 minor grammar fix 1998-07-26 12:59:40 +00:00
lukem b521b370b5 * spell `retrieved' correctly!
* parse Last-Modified: HTTP headers for date, and change time of
  retrieved file if parsing succeeded
* support file:/// and file://localhost/ URLs
* in url_get(), re-write byte moving code to consistently use fread()
  and fwrite(), and check errors at end with ferror()
* add about:* easter-egg (#ifndef SMALL :-)
1998-07-26 12:58:16 +00:00
lukem 8d879385dd * send 'Connection: close' in HTTP/1.1 headers, preventing the
remove server from using a persistent connection, which speeds
  up such requests.
* support http 301 and 302 redirects
* rewrite guts of url_get() to use fparseln() et al instead of
  read(s,&p,1)...  enables each in the header to be parsed
  as necessary
* rename login to ftp_login, to remove conflict with util.h::login
* cleanup verbose messages during http proxy requests
1998-07-22 16:06:27 +00:00
thorpej 7a12770f94 Add "sndbuf" and "rcvbuf" commands for setting the socket buffer sizes,
which in turn can allow the use of larger TCP windows.  This is a work in
progress; there is not yet support for specifying global defaults or
user prefrences on a host/network basis.
1998-07-10 04:39:03 +00:00
lukem 9a6e9b2ce7 some fixes & enhancements from openbsd's ftp, with extra fixes by me:
* default to passive with active fallback. $FTPMODE modifies this behaviour.
  -A forces active connection.
* support '-o outfile' for auto-fetched files. outfile can be a file,
  `-' (for stdout), or '|command' (to output each file through command).
* support '-r waittime', which retries the connection after waittime seconds
  if it fails.
* fix 'page file' when restart is non-zero.
* try all ip-addresses of a host in a http fetch (as the normal ftp fetch
  does).

XXX: a ``broken pipe'' error sometimes occurs with -o '|command';
i haven't tracked this down yet.
1998-06-04 08:28:35 +00:00
tv 063efa8267 Add the ability to work with HTTP-1.1-style virtual hosts, using the
HTTP/1.0 backwards compatible "Host:" field method.
1998-06-03 15:50:34 +00:00
christos 2187d01f57 - cast arg to is*() to unsigned char. 1998-05-20 00:54:26 +00:00
lukem 6ab4bdf006 define MAX_IN_PORT_T and use instead of USHRT_MAX. suggested by cgd@netbsd.org 1998-01-18 22:09:39 +00:00
lukem 7ee412ebee * ensure buffer for username is initialised, so ^D on username prompt
doesn't use garbage for the username.  from "Soren S. Jorvang" <soren@t.dk>
  in [bin/4559]
* use in_port_t for ports, and USHRT_MAX instead of 0xffff
  (from millert@openbsd.org)
* use `NULL' instead of `(.... *)0' where appropriate.
1998-01-18 14:23:33 +00:00
lukem d067f3bbd2 * in recvrequest(), ignore restart_point unless "RETR"ieving. fixes problems
where a remote completion or `mget' would confuse the client a `restart'
  had been issued beforehand. now, `restart' is remembered until an operation
  that can actually use it is invoked.
* in sendrequest(), don't reset restart_point upon entry. fixes `restart'
  for `put' operations.
* if `restart' is invoked with no arguments, print current setting instead
  of displaying a usage
* consistently use printf("%qd", (long long)restart_point) when displaying
  restart_point
* use strto[lq]() instead of atol() when parsing `mark' and `restart' values
* remove unnecessary strlen()s when result of previous snprintf() will do
* replace a few malloc()/strcpy()s with strdup()s
* use SECSPERHOUR instead of '3600'
1997-11-01 14:36:49 +00:00
lukem 8732be2e09 More cleanups from Todd Miller <Todd.Miller@courtesan.com>:
* Use an int, not "union wait".
* Move the "parsed_url" label so that the next statement is not an "else" --
  some ansi C compilers don't like it the old way (SGI's for example).
* Deal with the possibility of getlogin(2) failing.
* Don't error out if the remote server doesn't support the "MDTM" command.
1997-09-21 01:06:30 +00:00
lukem 87453d32bd Fixes from Todd Miller <Todd.Miller@courtesan.com>:
* use size_t instead of int in places
* use symbolic constants when using access()
1997-09-13 09:05:52 +00:00
lukem 2fec2a28f5 bugs fixed:
* don't interpret '-' or '|' when a local filename is determined from
  the remote name (i.e, in mget, and in get with only one argument).
  This is implemented using an extra argument to recvrequest().
  Fixes a major security hole.
* clean up memory leak when using globulize()
* clean up a couple of comments
* fix wording in TNF copyright

features added:
* support for TIS fwtk gate-ftp servers:
	* read defaults from $FTPSERVER && $FTPSERVERPORT
	* start in gate-ftp mode if invoked as 'gate-ftp'
	* toggle or set with 'gate [host [port]]'
1997-08-18 10:20:13 +00:00
lukem 076ac8bdc3 Send \r with \n in http requests. Allow "content-length" to be missing.
From [bin/3891] by Krister Walfridsson <cato@ulysses.df.lth.se>
1997-07-20 12:49:26 +00:00
lukem b9d5554d5d * use RCSID() && COPYRIGHT() macros
* cleanup for WARNS=1 (including some ugly '(void)&var' bits wrapped in
  #ifdef __GNUC__ to shut up gcc warnings WRT setjmp/longjmp)
* use strtol() instead of atoi(), and more extensively check result of
  conversion
* use u_int16_t instead of short or int for TCP port addresses
1997-07-20 09:45:35 +00:00
lukem 4a8077f211 Provide a different error message than `invalid url' when an
auto-login ftp URL is used when $ftp_proxy is defined. It now prints:
	Auto-login using ftp URLs isn't supported when using $ftp_proxy
Should solve rest of [bin/3643].

Whilst this is inconsistant with the behaviour when $ftp_proxy isn't
defined, the following constraints apply:
* it's not possible to support ftp URL auto-login when $ftp_proxy is
  defined, since it uses http not ftp, and you can't `login' to http
  servers; fudging this would require a major rewrite of ftp anyway)
* silently ignoring $ftp_proxy and not using it if an ftp auto-login
  URL is given is bad user interface design)
* mrg & others will harrass me if I remove support for autologin ftp URLs
  when $ftp_proxy isn't defined, even though it made the behaviour
  consistant whether $ftp_proxy was set or not.
1997-06-29 06:34:50 +00:00
lukem c04e79d154 url_get(): use origline in some messages, simplifying them, and free up copy
of origline before returning. also, previous commit (fix for [bin/3643]) was
inspired by suggested fix in said PR by Alan Barrett <apb@iafrica.com>.
1997-05-23 18:54:18 +00:00