Commit Graph

60 Commits

Author SHA1 Message Date
is 135600f947 More format string cleanup by sommerfeld. 2000-10-11 14:46:00 +00:00
lukem e3cdb47e47 * implement parseport(), which takes a string and attempts to convert
it to a numeric port number
* use parseport() in parse_url() and hookup()
* don't try and lookup the port number using getaddrinfo(), as it's too hard
  to separate a failed host name lookup from a failed service name lookup.
  this was causing lossage on systems that don't have `http' in services(5)
  (such as solaris), but only crept in when we started using getaddrinfo()
  unconditionally.
2000-08-06 08:51:22 +00:00
lukem 7816d2586e add support for FEAT and OPTS commands with `features' and `opts'.
(from RFC 2389).

add support for MLST & MLSD (machine parseble listings) with 'mlst', 'mlsd'
and 'pmlsd' (mlsd |$PAGER) commands.  (from draft-ietf-ftpext-mlst-11)

rename remotesyst() to getremoteinfo(), and modify to parse the result from
FEAT (if supported), and take into account the support for the various
extensions such as MDTM, SIZE, REST (STREAM), MLSD, and FEAT/OPTS.
put each feature into one of the following categories:
	- known to work (explicit FEAT)
	- unknown but assume works until explicit failure, when it's
	  then tagged as `known not to work'.
	- known not to work (FEAT succeeded but didn't return anything,
	  or was unknown and then explicit failure)
assign results into features[] matrix.

add support to getreply() so that an optional callback will be called
for each line received from the server except for the first and last.
this is used in FEAT (and MLST) parsing.

modify various commands to check if REST (STREAM), MDTM and SIZE are
explicitly or implicitly supported before using.

fix `syst' when verbose is off.

minor knf (indent goto labels by one space, etc).

simply various command usage handlers by assuming that argv != NULL except
for quit() and disconnect().
2000-07-18 07:16:52 +00:00
lukem 040253276f * migrate the SYST parsing from setpeer() into a separate remotesyst().
call remotesyst() only when login has been successful
  some servers don't let you run SYST until you've successfully logged in.
* in fetch_ftp(), always call setpeer() with autologin disabled, and use
  the following ftp_login() to DTRT.
  this prevents ftp from trying to login a second time if the first autologin
  fails when connecting to a remote site anonymously using autofetch.
* reset unix_proxy and unix_server in cleanuppeer()
* missed a function conversion in the KNF sweep...
2000-06-15 13:08:23 +00:00
lukem 413a4004df 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>
2000-05-31 14:23:57 +00:00
itojun 288fc74e2e convert IPv4 mapped address (::ffff:10.1.1.1) into real IPv4 address
before touching it.  IPv4 mapped address complicates too many things
in FTP protocol handling.
2000-05-29 14:57:27 +00:00
lukem 2c9a4cf5d0 convert to ANSI KNF 2000-05-01 10:35:16 +00:00
lukem d16e624b57 * Add support for `fget localfile', which reads a list of filenames to
retrieve from localfile.  Based on work by Darren Reed.
* Crank version.
* Update copyright dates.
2000-05-01 09:44:53 +00:00
lukem 7044ee274b define private type `sigfunc' as
typedef void (*sigfunc) __P((int));
and replace use of sig_t and void (*)(int).

certain other OSes define sig_t differently to that (they add extra arguments),
and it causes problems due to function mismatches, etc...
2000-01-31 22:01:03 +00:00
lukem d0090fb777 * implement xsl_init() and xsl_add(); error checking forms of sl_{init,add}()
* fix bug where the second press of <TAB> on an empty word (i.e, list
  all options) may have resulted in an strncmp() against NULL.  (detected
  by _DIAGASSERT())
1999-11-28 06:32:04 +00:00
lukem ecb8a0755a - implement `set rprompt'; right side version of `set prompt'. depends on
EL_RPROMPT support i added to editline(3).
- allow $FTPPROMPT and $FTPRPROMPT to override defaults for the relevant
  prompts
- move `%' formatting code from prompt() to expandbuf().
- implement `%.' and `%c', similar to the same % codes in tcsh(1)
  (functionality I added to tcsh nearly 6 years ago), except that `%.'
  always does `...trailing' and `%c' always does `/<x>trailing'.
- unknown `%foo' codes get printed as `%foo'
1999-11-12 02:50:38 +00:00
lukem 14fbd5079e - implement updateremotepwd(); update the global variable `remotepwd'
to contain the remote working directory.
- add `set prompt', a user configurable prompt. (defaults to `ftp> ').
  the following escape characters a la tcsh(1) are supported: %/, %m,
  %M, and %n.
- add global var `username'; used by prompt code
- fix a couple of minor memory leaks
- bump version
1999-11-11 02:53:02 +00:00
lukem 4f2d3550d0 new features:
- add `usage'; displays the usage of a command.
  implemented by calling the c_handler() with argc = 0, argv = "funcname".
- add `passive auto'; does the same as $FTPMODE=auto.
- add `set [option value]'; display all options, or set an option to a value.
- add `unset option'; unset an option.
- add getoptionvalue() to retrieve an option's value, and replace a few
  global variables with calls to this.
- implement cleanuppeer(), which resets various bits of state back to
  `disconnected'. call in disconnect() and lostpeer().
- support completing on `options'.
- improve recovery after a SIGINT may have closed the connection.
  XXX: there's still a couple to fix

other stuff:
- various consistency fixes in the man page.
- ensure that the command usage strings in the code and man page match reality.
- mput/mget: check that the connection still exists before each xfer.
- minor cosmetic changes in confirm().
- set code correctly in sizecmd() and modtime()
- don't need \n in err() strings.
- change lostpeer to take an argument (rather than casting (sig_t)lostpeer
  in signal handlers)
- knf and whitespace police.
1999-10-24 12:31:36 +00:00
lukem f74df4b2ea * fix up confirm() (broke `a' and `p' in last commit)
* simplify main loop (don't need `top' variable any more)
* use a struct sockaddr_in6.sin6_addr for the result from inet_pton(),
  rather than u_char buf[16]
* add a few more comments
1999-10-13 02:47:54 +00:00
lukem da626f2307 a few user interface and cosmetic tweaks:
* confirm(): move from util.c to cmds.c. display mnemonic string in its prompt.
  add support for `q' (terminate current xfer), `?' (show help list)
* in various signal handlers, output a linefeed only if fromatty.
* if fgets(stdin) returned NULL (i.e, EOF), clearerr(stdin) because you don't
  want future fgets to fail. this is not done for the fgets() in the main
  command loop, since ftp will quit at that point.
* unless ftp is invoked with -a, don't retain the anonftp setting between
  hosts (`ftp somehost:' sets anonftp, but you don't want that to `stick'
  if you close that connection and open a new one).
1999-10-12 06:04:59 +00:00
lukem afb965e778 allow a second SIGINT during the "xfer aborted. waiting for remote to finish abort."
stage. if this occurs, just call lostpeer() to close the connection.  whilst this
might be considered brutal, it's also extremely handy if you're impatient or there's
lossage at the remote end.
1999-10-09 12:48:12 +00:00
lukem a53d7d57a9 * use sigsetjmp()/siglongjump() instead of setjmp()/longjmp(); the latter
don't save the signal mask on some foreign systems.
* ensure signal handlers don't use stdio and do reset errno if they
  don't exit with siglongjmp()
* use a common SIGINT handler for {send,recv}request()
1999-10-09 03:00:55 +00:00
lukem f45505380a add TNFi copyright to all files i've done more than a minor amount of work to... 1999-10-05 01:16:11 +00:00
lukem 4309cfaab3 enhancments from Marc Horowitz <marc@mit.edu> to improve connection timeouts:
* implement xsignal_restart(), which only sets the SA_RESTART flag if
  specifically requested
* xsignal() is now a wrapper to xsignal_restart(). INFO, USR1, USR2 and WINCH
  are restartable, ALRM, INT, PIPE and QUIT are not.
* improve getreply()'s timeout code to take advantage of the above.

other changes:
* improve wording of how globbing works for `classic' URLs (host:path).
  suggested by John Refling <johnr@imageworks.com> in relation to PRs
  [bin/8519] and [bin/8520]
* always compile in the `edit' command even if NO_EDITCOMPLETE defined.
  it's just a no-op in the latter case, which is more consistent to
  the users.
* always compile in about: support (i.e, remove NO_ABOUT).
  i'm entitled to some vanity in this program...
* clean up some whitespace
1999-10-05 00:54:07 +00:00
lukem ad70c1982e prefix the global variables in ftp_var.h with GLOBAL, which defaults
to "extern" if it's not set. define GLOBAL to (empty) in main.c.
this effectively moves all the globals into main.c whilst retaining
namespace access to them in other source files.
(global vars in header files confuse foreign linkers)
1999-10-01 06:55:44 +00:00
lukem 25790d921d * In the !NI_NUMERICHOST case (i.e, getaddrinfo() challenged systems), portnum
should be in host order. found/fixed by Matthias Pfaller <leo@dachau.marco.de>
* parse_url(): improve checking of portnum, and add an extra argument to pass
  back the parsed portnum to the caller (reduces a bit of code duplication)
* Move the KAME/WIDE copyrights after the BSD/TNFi ones. Since there was
  significantly less code added under the former, it's only fair on the latter.
1999-09-30 23:51:26 +00:00
lukem 1b3e840242 * fix initialisation of home[]
* fetch_url(): if path would be NULL, return strdup("")
1999-09-30 12:18:03 +00:00
lukem 256fc138f1 * add new commands:
lpage	page local files
	pdir	as dir, but through your $PAGER
	pls	as ls, but through your $PAGER
* implement docase() (a la dotrans() et al) and use appropriately, rototilling
  some duplicated code
* globulize(): modify to return a pointer to the strdup()ed result in all cases,
  and hack the code that calls it to take this into account
* replace strcpy() and strncpy() with strlcpy()
* put(), getit(): use some aptly named local vars instead of argv[...]
* delint
1999-09-28 06:47:38 +00:00
lukem 002c3f9216 * idle(): rename to idlecmd(). certain linux distributions have an incompatible
prototype for idle() in <unistd.h> (which i thought was against namespace
  and sensibility guidelines, but...)
* consistently use xsignal() instead of signal(). we get known behaviour
  in all cases (SA_RESTART), which is good for some borken foreign systems.
* remove signal.h from most files; it's unnecessary now
* fetch_url(): use `long chunksize' instead of ssize_t; it's more portable, and
  we're setting chunksize with strtol() anyway
* xsignal(): only use SA_RESTART if it exists. SunOS 4.x doesn't have it
  but has the inverse (SA_INTERRUPT). the original function i was inspired
  from had this support (lib/signal.c, W. Richard Stevens' `UNP 2nd ed Vol 1').
* remove <termios.h> from util.c; it should be unnecessary now
1999-09-27 23:32:31 +00:00
lukem 75e3195cad * replace ifdefs against __SVR4 and __linux__ with DIRENT_MISSING_D_NAMLEN;
it's more portable and more obvious
* remove the mkgmtime() && HAVE_TIMEGM stuff:
	a) why should netbsd have to define HAVE_TIMEGM to compile cleanly?
	b) foreign compiles of ftp should just be linked with working
	   timegm function

a more portable version of this ftp client will be released as a 3rdparty
product; no use polluting our code with half-baked attempts...
1999-09-26 02:00:12 +00:00
lukem 700e3c1ec7 * add support for `xferbuf', which sets both `sndbuf' and `rcvbuf'
* document the above three commands
* rototill the way the sndbuf and rcvbuf work. remove resetsockbufsize()
* use the appropriate socket buffer size as the size of the buffer that
  the read()/write() loops use. speeds up things in some cases.
1999-09-22 07:18:31 +00:00
lukem 375a0efb60 * change fetch_ftp() to be fully rfc 1738 compliant; if the URL contains
the an empty directory (e.g, between `some' and `path' in
  `ftp://host/some//path'), then execute `CWD ' (without a path).
  This command will probably fail on rfc 959 compliant servers, so
  issue a warning in this case and bail. [noted by cgd].
  (i wonder if the people who wrote rfc 1738 actually realised that this
  requirement appears to contravene the spec for `cwd' in rfc 959 ?)
* replace isurl() with isipv6addr(), and use appropriately. fixes
  auto-login with `classic ftp URLs' (e.g, `ftp somehost:')
* cleanup and rework some of the ipv6 stuff in parse_url()
* prevent potential coredump in fetch_ftp() when parsing `;type=X'
* KNF a few lines
* fix a couple of comments
* cleanup the man page a bit
1999-07-12 13:20:34 +00:00
itojun 940276557f add epsv4 command, which enable/disable the use of EPSV/EPRT.
this is mainly for (hypothetical) ftp server which disconnect clients
that use EPSV/EPRT.  I've never seen any ftp server like this, but
epsv4 command may be of use when such an ftp server is found.
1999-07-11 20:37:39 +00:00
itojun d1a8e792f7 add dual-stack (IPv4/v6) support. hope I broke no other part... 1999-07-02 08:07:40 +00:00
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
christos af43552363 remove declaration for empty; it is only used in one file and hide
it's implementation.
1999-06-24 14:46:59 +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 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
lukem 6cc6d5d262 changes to fix [bin/6951] by Peter Simons <simons@cys.de>:
* implement ftpvis(), which \ quotes the following in the given string:
  SP, TAB, \, CR, "
* use ftpvis() in complete_ambiguous(), to escape characters in a word
  which would confuse makeargv()/slurpstring().
1999-02-07 13:14:06 +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 688446255e * implement xsignal(); same semantics as signal() but uses sigaction
with an explicit SA_RESTART. (needed for portability)
* use xsignal() for SIGALRM and SIGINFO handlers
1998-08-08 06:46:01 +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
mycroft f56c79f70c const poisoning. 1998-07-26 21:47:47 +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
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 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 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 a9a78ba448 More enhancements/bugfixes (when will it end?)
* differentiate between being connected, and being logged in
* cleanup some text messages
* support username & password ftp URLs (ftp://user:pass@host/) in non-proxy
  situations; assume proxy supports it for proxy situations.
* cd to / before performing any autofetch transfers
* use strncasecmp in URL parsing. fix from <Todd.Miller@courtesan.com>
1997-04-14 09:09:15 +00:00
lukem d473547d56 * support $ftp_proxy for ftp:// transfers [bin/3245]
* add "more" & "less" as synonyms for "page"
* move editline setup code into controlediting(), and call appropriately.
  only setup setup terminal if going into interactive mode. inspired
  by Todd Miller <todd.miller@courtesan.com>
1997-04-05 03:27:32 +00:00
christos 067f3f2db4 SMALLFTP->SMALL; remove SMALL from Makefile 1997-03-14 01:39:31 +00:00
lukem 3b5054739d Features:
* support remglobbing of auto_fetch arguments
* new flag - '-e'; disable editing
* "page file" == "get file |${PAGER-less}"

Bugfixes/cleanup:
* consistently use a trailing '.' on messages
* code cleanup, including buffer overrun fixes, use puts
  and putchar in places, etc (inspired by OpenBSD mods)
* disable progress bar when local-file is a pipe or '-'
* skip \r in http headers
* fix remote ftpd slash bug more elegantly (so it works with ////)
* abort_remote(): check if cout==NULL before using it. should fix [bin/3273]
* fixed up cosmetic problems when complete_remote() generated errors from the
  remote server (such as "no files found", "login with user and pass", ...)
  done by adding extra argument to remglob(), which is a pointer to an error
  buffer to put messages in rather than printing to stdout.
1997-03-13 06:23:11 +00:00
lukem 3a50014d60 [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 10:44:54 +00:00