This is zsh.info, produced by makeinfo version 4.0 from ./zsh.texi.

INFO-DIR-SECTION Utilities
START-INFO-DIR-ENTRY
* ZSH: (zsh).                     The Z Shell Manual.
END-INFO-DIR-ENTRY


File: zsh.info,  Node: TCP Functions,  Next: TCP Parameters,  Up: TCP Function System

TCP User Functions
==================

Basic I/O
---------

tcp_open [-qz] HOST PORT [ SESS ]
tcp_open [-qz] [ -s SESS | -l SESS,... ] ...
tcp_open [-qz] [-a FD | -f FD ] [ SESS ]
     Open a new session.  In the first and simplest form, open a TCP
     connection to host HOST at port PORT; numeric and symbolic forms
     are understood for both.

     If SESS is given, this becomes the name of the session which can be
     used to refer to multiple different TCP connections.  If SESS is
     not given, the function will invent a numeric name value (note
     this is _not_ the same as the file descriptor to which the session
     is attached).  It is recommended that session names not include
     `funny' characters, where funny characters are not well-defined
     but certainly do not include alphanumerics or underscores, and
     certainly do include whitespace.

     In the second case, one or more sessions to be opened are given by
     name.  A single session name is given after -s and a
     comma-separated list after -l; both options may be repeated as
     many times as necessary.  The host and port are read from the file
     .ztcp_sessions in the same directory as the user's zsh
     initialisation files, i.e. usually the home directory, but
     $ZDOTDIR if that is set.  The file consists of lines each giving a
     session name and the corresponding host and port, in that order
     (note the session name comes first, not last), separated by
     whitespace.

     The third form allows passive and fake TCP connections.  If the
     option -a is used, its argument is a file descriptor open for
     listening for connections.  No function front-end is provided to
     open such a file descriptor, but a call to `ztcp -l PORT' will
     create one with the file descriptor stored in the parameter
     $REPLY.  The listening port can be closed with `ztcp -c FD'.  A
     call to `tcp_open -a FD' will block until a remote TCP connection
     is made to PORT on the local machine.  At this point, a session is
     created in the usual way and is largely indistinguishable from an
     active connection created with one of the first two forms.

     If the option -f is used, its argument is a file descriptor which
     is used directly as if it were a TCP session.  How well the
     remainder of the TCP function system copes with this depends on
     what actually underlies this file descriptor.  A regular file is
     likely to be unusable; a FIFO (pipe) of some sort will work
     better, but note that it is not a good idea for two different
     sessions to attempt to read from the same FIFO at once.

     If the option -q is given with any of the three forms, tcp_open
     will not print informational messages, although it will in any
     case exit with an appropriate status.

     If the line editor (zle) is in use, which it usually is if and
     only if the shell is interactive, tcp_open installs a handler
     inside zle which will check for new data at the same time as it
     checks for keyboard input.  This is convenient as the shell
     consumes no CPU time while waiting; the test is performed by the
     operating systems.  However, if incoming data is only to be read
     explicitly, the option -z to any of the forms of tcp_open prevents
     the handler from being installed.   Note this is not necessary for
     executing complete sets of send and read commands from a function,
     as zle is not active at this point.  Generally speaking, the
     handler is only active when the shell is waiting for input at a
     command prompt or in the vared builtin.  The option has no effect
     if zle is not active; `[[ -o zle]]' will test for this.

     The first session to be opened becomes the current session;
     subsequent calls to tcp_open will not change this.  The current
     session is stored in the parameter $TCP_SESS; see below for more
     detail about the parameters used by the system.

tcp_close [-qn] [ -a | -l SESS,... | SESS ... ]
     Close the named sessions, or the current session if none is given,
     or all open sessions if -a is given.  The options -l and -s are
     both handled for consistency with tcp_open, although the latter is
     redundant.

     If the session being closed is the current one, $TCP_SESS is unset,
     leaving no current session, even if there are other sessions still
     open.

     If the session was opened with tcp_open -f, the file descriptor is
     closed so long as it is in the range 0 to 9 accessible directly
     from the command line.  If the option -n is given, no attempt will
     be made to close file descriptors in this case.  The -n option is
     not used for genuine ztcp session; the file descriptors are always
     closed with the session.

     If the option -q is given, no informational messages will be
     printed.

tcp_read [-bdq] [ -t TO ] [ -T TO ]
[ -a | -u FD ... | -l SESS,... | -s SESS ...]
     Perform a read operation on the current session, or on a list of
     sessions if any are given (the first form), or all open sessions
     (the second form).  Any of the -u, -l or -s options may be
     repeated or mixed together.  The -u option specifies a file
     descriptor directly (only those managed by this system are
     useful), the other two specify sessions as described for tcp_open
     above.  If -a is given, all sessions ares examined for new data.

     The function checks for new data available on all the sessions
     listed.  Unless the -b option is given, it will not block waiting
     for new data.  Any one line of data from any of the available
     sessions will be read, stored in the parameter $TCP_LINE, and
     displayed to standard output unless $TCP_SILENT contains a
     non-empty string.  When printed to standard output the string
     $TCP_PROMPT will be shown at the start of the line; the default
     form for this includes the name of the session being read.  See
     below for more information on these parameters.  In this mode,
     tcp_read can be called repeatedly until it returns status 2 which
     indicates all pending input from all specified sessions has been
     handled.

     With the option -b, equivalent to an infinite timeout, the function
     will block until a line is available to read from one of the
     specified sessions.  However, only a single line is returned.

     The option -d indicates that all pending input should be drained.
     In this case tcp_read may process multiple lines in the manner
     given above; only the last is stored in $TCP_LINE, but the
     complete set is stored in the array $tcp_lines.  This is cleared
     at the start of each call to tcp_read.

     The options -t and -T specify a timeout in seconds, which may be a
     floating point number for increased accuracy.  With -t the timeout
     is applied before each line read.  With -T, the timeout applies to
     the overall operation, possibly including multiple read operations
     if the option -d is present; without this option, there is no
     distinction between -t and -T.

     The function does not print informational messages, but if the
     option -q is given, no error message is printed for a non-existent
     session.

     A return value of 2 indicates a timeout or no data to read.  Any
     other non-zero return value indicates some error condition.

     See tcp_log for how to control where data is sent by tcp_read.

tcp_send [-nq] [ -s SESS | -l SESS,... ] DATA ...
tcp_send [-nq] -a DATA ...
     Send the supplied data strings to all the specified sessions in
     turn.  The underlying operation differs little from a `print -r'
     to the session's file descriptor, although it attempts to prevent
     the shell from dying owing to a SIGPIPE caused by an attempt to
     write to a defunct session.

     The option -n prevents tcp_send from putting a newline at the end
     of the data strings.

     The remaining options all behave as for tcp_read.

     The data arguments are not further processed once they have been
     passed to tcp_send; they are simply passed down to print -r.

     If the parameter $TCP_OUTPUT is a non-empty string and logging is
     enabled then the data sent to each session will be echoed to the
     log file(s) with $TCP_OUTPUT in front where appropriate, much in
     the manner of $TCP_PROMPT.

Session Management
------------------

tcp_alias [-q] ALIAS=SESS ...
tcp_alias [-q] [ ALIAS ] ...
tcp_alias -d [-q] ALIAS ...
     This function is not particularly well tested.

     The first form creates an alias for a session name; ALIAS can then
     be used to refer to the existing session SESS.  As many aliases
     may be listed as required.

     The second form lists any aliases specified, or all aliases if
     none.

     The third form deletes all the aliases listed.  The underlying
     sessions are not affected.

     The option -q suppresses an inconsistently chosen subset of error
     messages.

tcp_log [-asc] [ -n | -N ] [ LOGFILE ]
     With an argument LOGFILE, all future input from tcp_read will be
     logged to the named file.  Unless -a (append) is given, this file
     will first be truncated or created empty.  With no arguments, show
     the current status of logging.

     With the option -s, per-session logging is enabled.  Input from
     tcp_read is output to the file LOGFILE.SESS.  As the session is
     automatically discriminated by the filename, the contents are raw
     (no $TCP_PROMPT).  The option  -a applies as above.  Per-session
     logging and logging of all data in one file are not mutually
     exclusive.

     The option -c closes all logging, both complete and per-session
     logs.

     The options -n and -N respectively turn off or restore output of
     data read by tcp_read to standard output; hence `tcp_log -cn' turns
     off all output by tcp_read.

     The function is purely a convenient front end to setting the
     parameters $TCP_LOG, $TCP_LOG_SESS, $TCP_SILENT, which are
     described below.

tcp_rename OLD NEW
     Rename session OLD to session NEW.  The old name becomes invalid.

tcp_sess [ SESS [ COMMAND  ... ] ]
     With no arguments, list all the open sessions and associated file
     descriptors.  The current session is marked with a star.  For use
     in functions, direct access to the parameters $tcp_by_name,
     $tcp_by_fd and $TCP_SESS is probably more convenient; see below.

     With a SESS argument, set the current session to SESS.  This is
     equivalent to changing $TCP_SESS directly.

     With additional arguments, temporarily set the current session
     while executing the string command ....  The first argument is
     re-evaluated so as to expand aliases etc., but the remaining
     arguments are passed through as the appear to tcp_sess.  The
     original session is restored when tcp_sess exits.

Advanced I/O
------------

tcp_command SEND-OPTIONS ... SEND-ARGUMENTS ...
     This is a convenient front-end to tcp_send.  All arguments are
     passed to tcp_send, then the function pauses waiting for data.
     While data is arriving at least every $TCP_TIMEOUT (default 0.3)
     seconds, data is handled and printed out according to the current
     settings.  Status 0 is always returned.

     This is generally only useful for interactive use, to prevent the
     display becoming fragmented by output returned from the
     connection.  Within a programme or function it is generally better
     to handle reading data by a more explicit method.

tcp_expect [ -q ] [ -p VAR ] [ -t  TO | -T TO]
    [ -a | -s SESS ... | -l SESS,... ] PATTERN ...
     Wait for input matching any of the given PATTERNs from any of the
     specified sessions.  Input is ignored until an input line matches
     one of the given patterns; at this point status zero is returned,
     the matching line is stored in $TCP_LINE, and the full set of
     lines read during the call to tcp_expect is stored in the array
     $tcp_expect_lines.

     Sessions are specified in the same way as tcp_read: the default is
     to use the current session, otherwise the sessions specified by -a,
     -s, or -l are used.

     Each PATTERN is a standard zsh extended-globbing pattern; note
     that it needs to be quoted to avoid it being expanded immediately
     by filename generation.  It must match the full line, so to match
     a substring there must be a `*' at the start and end.  The line
     matched against includes the $TCP_PROMPT added by tcp_read.  It is
     possible to include the globbing flags `#b' or `#m' in the
     patterns to make backreferences available in the parameters
     $MATCH, $match, etc., as described in the base zsh documentation
     on pattern matching.

     Unlike tcp_read, the default behaviour of tcp_expect is to block
     indefinitely until the required input is found.  This can be
     modified by specifying a timeout with -t or -T; these function as
     in tcp_read, specifying a per-read or overall timeout,
     respectively, in seconds, as an integer or floating-point number.
     As tcp_read, the function returns status 2 if a timeout occurs.

     The function returns as soon as any one of the patterns given
     match.  If the caller needs to know which of the patterns matched,
     the option -p VAR can be used; on return, $var is set to the
     number of the pattern using ordinary zsh indexing, i.e. the first
     is 1, and so on.  Note the absence of a `$' in front of VAR.  To
     avoid clashes, the parameter cannot begin with `_expect'.

     The option -q is passed directly down to tcp_read.

     As all input is done via tcp_read, all the usual rules about
     output of lines read apply.  One exception is that the parameter
     $tcp_lines will only reflect the line actually matched by
     tcp_expect; use $tcp_expect_lines for the full set of lines read
     during the function call.

tcp_proxy
     This is a simple-minded function to accept a TCP connection and
     execute a command with I/O redirected to the connection.  Extreme
     caution should be taken as there is no security whatsoever and
     this can leave your computer open to the world.  Ideally, it
     should only be used behind a firewall.

     The first argument is a TCP port on which the function will listen.

     The remaining arguments give a command and its arguments to
     execute with standard input, standard output and standard error
     redirected to the file descriptor on which the TCP session has
     been accepted.  If no command is given, a new zsh is started.
     This gives everyone on your network direct access to your account,
     which in many cases will be a bad thing.

     The command is run in the background, so tcp_proxy can then accept
     new connections.  It continues to accept new connections until
     interrupted.

tcp_spam [-rtv] [ -a | -s  SESS | -l SESS,... ] CMD ...
     Execute `CMD ...' for each session in turn.  Note this executes
     the command and arguments; it does not send the command line as
     data unless the -t (transmit) option is given.

     The sessions may be selected explicitly with the standard -a, -s or
     -l options, or may be chosen implicitly.  If none of the three
     options is given the rules are: first, if the array $tcp_spam_list
     is set, this is taken as the list of sessions, otherwise all
     sessions are taken.  Second, any sessions given in the array
     $tcp_no_spam_list are removed from the list of sessions.

     Normally, any sessions added by the `-a' flag or when all sessions
     are chosen implicitly are spammed in alphabetic order; sessions
     given by the $tcp_spam_list array or on the command line are
     spammed in the order given.  The -r flag reverses the order
     however it was arrived it.

     The -v flag specifies that a $TCP_PROMPT will be output before each
     session.  This is output after any modification to TCP_SESS by the
     user-defined tcp_on_spam function described below.  (Obviously that
     function is able to generate its own output.)

tcp_talk
     This is a fairly simple-minded attempt to force input to the line
     editor to go straight to the default TCP_SESSION.

     An escape string, $TCP_TALK_ESCAPE, default `:', is used to allow
     access to normal shell operation.  If it is on its own at the
     start of the line, or followed only by whitespace, the line editor
     returns to normal operation.  Otherwise, the string and any
     following whitespace are skipped and the remainder of the line
     executed as shell input without any change of the line editor's
     operating mode.

     The current implementation is somewhat deficient in terms of use
     of the command history.  For this reason, many users will prefer
     to use some form of alternative approach for sending data easily
     to the current session.  One simple approach is to alias some
     special character (such as `%') to `tcp_command -'.

tcp_wait
     The sole argument is an integer or floating point number which
     gives the seconds to delay.  The shell will do nothing for that
     period except wait for input on all TCP sessions by calling
     tcp_read -a.  This is similar to the interactive behaviour at the
     command prompt when zle handlers are installed.

TCP User-defined Function
=========================

Certain functions, if defined by the user, will be called by the
function system in certain contexts.  This facility depends on the
module zsh/parameter, which is usually available in interactive shells
as the completion system depends on it.  None of the functions need by
defined; they simply provide convenient hooks when necessary.

Typically, these are called after the requested action has been taken,
so that the various parameters will reflect the new state.

tcp_on_alias ALIAS FD
     When an alias is defined, this function will be called with two
     arguments: the name of the alias, and the file descriptor of the
     corresponding session.

tcp_on_close SESS FD
     This is called with the name of a session being closed and the file
     descriptor which corresponded to that session.  Both will be
     invalid by the time the function is called.

tcp_on_open SESS FD
     This is called after a new session has been defined with the
     session name and file descriptor as arguments.

tcp_on_rename OLDSESS FD NEWSESS
     This is called after a session has been renamed with the three
     arguments old session name, file descriptor, new session name.

tcp_on_spam SESS COMMAND ...
     This is called once for each session spammed, just _before_ a
     command is executed for a session by tcp_spam.  The arguments are
     the session name followed by the command list to be executed.  If
     tcp_spam was called with the option -t, the first command will be
     tcp_send.

     This function is called after $TCP_SESS is set to reflect the
     session to be spammed, but before any use of it is made.  Hence it
     is possible to alter the value of $TCP_SESS within this function.
     For example, the session arguments to tcp_spam could include extra
     information to be stripped off and processed in tcp_on_spam.

     If the function sets the parameter $REPLY to `done', the command
     line is not executed; in addition, no prompt is printed for the -v
     option to tcp_spam.

tcp_on_unalias ALIAS FD
     This is called with the name of an alias and the corresponding
     session's file descriptor after an alias has been deleted.

TCP Utility Functions
=====================

The following functions are used by the TCP function system but will
rarely if ever need to be called directly.

tcp_fd_handler
     This is the function installed by tcp_open for handling input from
     within the line editor, if that is required.  It is in the format
     documented for the builtin `zle -F' in *Note Zle Builtins:: .

tcp_output [ -q ] -P PROMPT -F FD -S SESS
     This function is used for both logging and handling output to
     standard output, from within tcp_read and (if $TCP_OUTPUT is set)
     tcp_send.

     The PROMPT to use is specified by -P; the default is the empty
     string.  It can contain `%s' which is replaced by the session
     name, or `%f' which is replaced by the session's file descriptor;
     `%%' is replaced by a single `%'.

     The option -q suppresses output to standard output, but not to any
     log files which are configured.

     The -S and -F options are used to pass in the session name and file
     descriptor for possible replacement in the prompt.


File: zsh.info,  Node: TCP Parameters,  Next: TCP Examples,  Prev: TCP Functions,  Up: TCP Function System

TCP User Parameters
===================

Parameters follow the usual convention that uppercase is used for
scalars and integers, while lowercase is used for normal and
associative array.  It is always safe for user code to read these
parameters; some parameters may also be set, which are noted
explicitly.  Other are included in this group as they are set by the
function system for the user's benefit, i.e. setting them is typically
not useful but is benign.

It is often also useful to make settable parameters local to a function.
For example, `local TCP_SILENT=1' specifies that data read during the
function call will not be printed to standard output, regardless of the
setting outside the function.  Likewise, `local TCP_SESS=SESS' sets a
session for the duration of a function.

tcp_expect_lines
     Array.  The set of lines read during the last call to tcp_expect,
     including the last ($TCP_LINE).

tcp_filter
     Array. May be set directly.  A set of extended globbing patterns
     which, if matched in tcp_output, will cause the line not to be
     printed to standard output.  The patterns should be defined as
     described for the arguments to tcp_expect.  Output of line to log
     files is not affected.

TCP_LINE
     The last line read by tcp_read, and hence also tcp_expect.

TCP_LINE_FD
     The file descriptor from which $TCP_LINE was read.
     ${tcp_by_fd[$TCP_LINE_FD]} will give the corresponding session
     name.

tcp_lines
     Array. The set of lines read during the last call to tcp_read,
     including the last ($TCP_LINE).

TCP_LOG
     May be set directly, although it is also controlled by tcp_log.
     The name of a file to which output from all sessions will be sent.
     The output is proceeded by the usual $TCP_PROMPT.  If it is not an
     absolute path name, it will follow the user's current directory.

TCP_LOG_SESS
     May be set directly, although it is also controlled by tcp_log.
     The prefix for a set of files to which output from each session
     separately will be sent; the full filename is ${TCP_LOG_SESS}.SESS.
     Output to each file is raw; no prompt is added.  If it is not an
     absolute path name, it will follow the user's current directory.

tcp_nospam_list
     Array.  May be set directly.  See tcp_spam for how this is used.

TCP_OUTPUT
     May be set directly.  If a non-empty string, any data sent to a
     session by tcp_send will be logged.  The prompt has the same
     format as TCP_PROMPT and the same rules for its use apply:  it is
     used in a file specified by $TCP_LOG, but not in a file generated
     from $TCP_LOG_SESS.

TCP_PROMPT
     May be set directly.  Used as the prefix for data read by tcp_read
     which is printed to standard output or to the log file given by
     $TCP_LOG, if any.  Any `%s', `%f' or `%%' occurring in the string
     will be replaced by the name of the session, the session's
     underlying file descriptor, or a single `%', respectively.

TCP_READ_DEBUG
     May be set directly.  If this has non-zero length, tcp_read will
     give some limited diagnostics about data being read.

TCP_SESS
     May be set directly.  The current session; must refer to one of the
     sessions established by tcp_open.

TCP_SILENT
     May be set directly, although it is also controlled by tcp_log.
     If of non-zero length, data read by tcp_read will not be written to
     standard output, though may still be written to a log file.

tcp_spam_list
     Array.  May be set directly.  See the description of the function
     tcp_spam for how this is used.

TCP_TALK_ESCAPE
     May be set directly.  See the description of the function tcp_talk
     for how this is used.

TCP_TIMEOUT
     May be set directly.  Currently this is only used by the function
     tcp_command, see above.

TCP Utility Parameters
======================

These parameters are controlled by the function system; they may be read
directly, but should not usually be set by user code.

tcp_aliases
     Associative array.  The keys are the names of sessions established
     with tcp_open; each value is a space-separated list of aliases
     which refer to that session.

tcp_by_fd
     Associative array.  The keys are session file descriptors; each
     value is the name of that session.

tcp_by_name
     Associative array.  The keys are the names of sessions; each value
     is the file descriptor associated with that session.


File: zsh.info,  Node: TCP Examples,  Next: TCP Bugs,  Prev: TCP Parameters,  Up: TCP Function System

TCP Examples
============

Here is a trivial example using a remote calculator.

TO create a calculator server on port 7337 (see the dc manual page for
quite how infuriating the underlying command is):

     tcp_proxy 7337 dc

To connect to this from the same host with a session also named `dc':

     tcp_open localhost 7337 dc

To send a command to the remote session and wait a short while for
output (assuming dc is the current session):

     tcp_command 2 4 + p

To close the session:

     tcp_close

The tcp_proxy needs to be killed to be stopped.  Note this will not
usually kill any connections which have already been accepted, and also
that the port is not immediately available for reuse.

The following chunk of code puts a list of sessions into an xterm
header, with the current session followed by a star.

     print -n "\033]2;TCP:" ${(k)tcp_by_name:/$TCP_SESS/$TCP_SESS\*} "\a"


File: zsh.info,  Node: TCP Bugs,  Prev: TCP Examples,  Up: TCP Function System

TCP Bugs
========

The function tcp_read uses the shell's normal read builtin.  As this
reads a complete line at once, data arriving without a terminating
newline can cause the function to block indefinitely.

Though the function suite works well for interactive use and for data
arriving in small amounts, the performance when large amounts of data
are being exchanged is likely to be extremely poor.


File: zsh.info,  Node: Zftp Function System,  Next: User Contributions,  Prev: TCP Function System,  Up: Top

Zftp Function System
********************

Description
===========

This describes the set of shell functions supplied with the source
distribution as an interface to the zftp builtin command, allowing you
to perform FTP operations from the shell command line or within
functions or scripts.  The interface is similar to a traditional FTP
client (e.g. the ftp command itself, see man page ftp(1)), but as it is
entirely done within the shell all the familiar completion, editing and
globbing features, and so on, are present, and macros are particularly
simple to write as they are just ordinary shell functions.

The prerequisite is that the zftp command, as described in *Note The
zsh/zftp Module:: , must be available in the version of zsh installed
at your site.  If the shell is configured to load new commands at run
time, it probably is: typing `zmodload zsh/zftp' will make sure (if
that runs silently, it has worked).  If this is not the case, it is
possible zftp was linked into the shell anyway: to test this, type
`which zftp' and if zftp is available you will get the message `zftp:
shell built-in command'.

Commands given directly with zftp builtin may be interspersed between
the functions in this suite; in a few cases, using zftp directly may
cause some of the status information stored in shell parameters to
become invalid.  Note in particular the description of the variables
$ZFTP_TMOUT, $ZFTP_PREFS and $ZFTP_VERBOSE for zftp.

* Menu:

* Installation::
* Zftp Functions::
* Miscellaneous Features::


File: zsh.info,  Node: Installation,  Next: Zftp Functions,  Up: Zftp Function System

Installation
============

You should make sure all the functions from the Functions/Zftp
directory of the source distribution are available; they all begin with
the two letters `zf'.  They may already have been installed on your
system; otherwise, you will need to find them and copy them.  The
directory should appear as one of the elements of the $fpath array
(this should already be the case if they were installed), and at least
the function zfinit should be autoloaded; it will autoload the rest.
Finally, to initialize the use of the system you need to call the
zfinit function.  The following code in your .zshrc will arrange for
this; assume the functions are stored in the directory ~/myfns:

     fpath=(~/myfns $fpath)
     autoload -U zfinit
     zfinit

Note that zfinit assumes you are using the zmodload method to load the
zftp command.  If it is already built into the shell, change zfinit to
zfinit -n.  It is helpful (though not essential) if the call to zfinit
appears after any code to initialize the new completion system, else
unnecessary compctl commands will be given.


File: zsh.info,  Node: Zftp Functions,  Next: Miscellaneous Features,  Prev: Installation,  Up: Zftp Function System

Functions
=========

The sequence of operations in performing a file transfer is essentially
the same as that in a standard FTP client.  Note that, due to a quirk
of the shell's getopts builtin, for those functions that handle options
you must use `--' rather than `-' to ensure the remaining arguments are
treated literally (a single `-' is treated as an argument).

Opening a connection
--------------------

zfparams [ HOST [ USER [ PASSWORD ... ] ] ]
     Set or show the parameters for a future zfopen with no arguments.
     If no arguments are given, the current parameters are displayed
     (the password will be shown as a line of asterisks).  If a host is
     given, and either the USER or PASSWORD is not, they will be
     prompted for; also, any parameter given as `?' will be prompted
     for, and if the `?' is followed by a string, that will be used as
     the prompt.  As zfopen calls zfparams to store the parameters,
     this usually need not be called directly.

     A single argument `-' will delete the stored parameters.  This will
     also cause the memory of the last directory (and so on) on the
     other host to be deleted.

zfopen [ -1 ] [ HOST [ USER [ PASSWORD [ ACCOUNT ] ] ] ]
     If HOST is present, open a connection to that host under username
     USER with password PASSWORD (and, on the rare occasions when it is
     necessary, account ACCOUNT).  If a necessary parameter is missing
     or given as `?' it will be prompted for.  If HOST is not present,
     use a previously stored set of parameters.

     If the command was successful, and the terminal is compatible with
     xterm or is sun-cmd, a summary will appear in the title bar,
     giving the local host:directory and the remote host:directory;
     this is handled by the function zftp_chpwd, described below.

     Normally, the HOST, USER and PASSWORD are internally recorded for
     later re-opening, either by a zfopen with no arguments, or
     automatically (see below).  With the option `-1', no information is
     stored.  Also, if an open command with arguments failed, the
     parameters will not be retained (and any previous parameters will
     also be deleted).  A zfopen on its own, or a zfopen -1, never
     alters the stored parameters.

     Both zfopen and zfanon (but not zfparams) understand URLs of the
     form ftp://HOST/PATH... as meaning to connect to the HOST, then
     change directory to PATH (which must be a directory, not a file).
     The `ftp://' can be omitted; the trailing `/' is enough to trigger
     recognition of the PATH.  Note prefixes other than `ftp:' are not
     recognized, and that all characters after the first slash beyond
     HOST are significant in PATH.

zfanon [ -1 ] HOST
     Open a connection HOST for anonymous FTP.  The username used is
     `anonymous'.  The password (which will be reported the first time)
     is generated as USER@HOST; this is then stored in the shell
     parameter $EMAIL_ADDR which can alternatively be set manually to a
     suitable string.

Directory management
--------------------

zfcd [ DIR ]
zfcd -
zfcd OLD NEW
     Change the current directory on the remote server:  this is
     implemented to have many of the features of the shell builtin cd.

     In the first form with DIR present, change to the directory DIR.
     The command `zfcd ..' is treated specially, so is guaranteed to
     work on non-UNIX servers (note this is handled internally by
     zftp).  If DIR is omitted, has the effect of `zfcd ~'.

     The second form changes to the directory previously current.

     The third form attempts to change the current directory by
     replacing the first occurrence of the string OLD with the string
     NEW in the current directory.

     Note that in this command, and indeed anywhere a remote filename is
     expected, the string which on the local host corresponds to `~' is
     converted back to a `~' before being passed to the remote machine.
     This is convenient because of the way expansion is performed on
     the command line before zfcd receives a string.  For example,
     suppose the command is `zfcd ~/foo'.  The shell will expand this
     to a full path such as `zfcd /home/user2/pws/foo'.  At this stage,
     zfcd recognises the initial path as corresponding to `~' and will
     send the directory to the remote host as ~/foo, so that the `~'
     will be expanded by the server to the correct remote host
     directory.  Other named directories of the form `~name' are not
     treated in this fashion.

zfhere
     Change directory on the remote server to the one corresponding to
     the current local directory, with special handling of `~' as in
     zfcd.  For example, if the current local directory is ~/foo/bar,
     then zfhere performs the effect of `zfcd ~/foo/bar'.

zfdir [ -rfd ] [ - ] [ DIR-OPTIONS ] [ DIR ]
     Produce a long directory listing.  The arguments DIR-OPTIONS and
     DIR are passed directly to the server and their effect is
     implementation dependent, but specifying a particular remote
     directory DIR is usually possible.  The output is passed through a
     pager given by the environment variable $PAGER, or `more' if that
     is not set.

     The directory is usually cached for re-use.  In fact, two caches
     are maintained.  One is for use when there is no DIR-OPTIONS or
     DIR, i.e. a full listing of the current remote directory; it is
     flushed when the current remote directory changes.  The other is
     kept for repeated use of zfdir with the same arguments; for
     example, repeated use of `zfdir /pub/gnu' will only require the
     directory to be retrieved on the first call.  Alternatively, this
     cache can be re-viewed with the -r option.  As relative
     directories will confuse zfdir, the -f option can be used to force
     the cache to be flushed before the directory is listed.  The
     option -d will delete both caches without showing a directory
     listing; it will also delete the cache of file names in the
     current remote directory, if any.

zfls [ LS-OPTIONS ] [ DIR ]
     List files on the remote server.  With no arguments, this will
     produce a simple list of file names for the current remote
     directory.  Any arguments are passed directly to the server.  No
     pager and no caching is used.

Status commands
---------------

zftype [ TYPE ]
     With no arguments, show the type of data to be transferred,
     usually ASCII or binary.  With an argument, change the type: the
     types `A' or `ASCII' for ASCII data and `B' or `BINARY', `I' or
     `IMAGE' for binary data are understood case-insensitively.

zfstat [ -v ]
     Show the status of the current or last connection, as well as the
     status of some of zftp's status variables.  With the -v option, a
     more verbose listing is produced by querying the server for its
     version of events, too.

Retrieving files
----------------

The commands for retrieving files all take at least two options. -G
suppresses remote filename expansion which would otherwise be performed
(see below for a more detailed description of that).  -t attempts to
set the modification time of the local file to that of the remote file:
this requires version 5 of perl, see the description of the function
zfrtime below for more information.

zfget [ -Gtc ] FILE1 ...
     Retrieve all the listed files FILE1 ... one at a time from the
     remote server.  If a file contains a `/', the full name is passed
     to the remote server, but the file is stored locally under the
     name given by the part after the final `/'.  The option -c (cat)
     forces all files to be sent as a single stream to standard output;
     in this case the -t option has no effect.

zfuget [ -Gvst ] FILE1 ...
     As zfget, but only retrieve files where the version on the remote
     server is newer (has a later modification time), or where the
     local file does not exist.  If the remote file is older but the
     files have different sizes, or if the sizes are the same but the
     remote file is newer, the user will usually be queried.  With the
     option -s, the command runs silently and will always retrieve the
     file in either of those two cases.  With the option -v, the
     command prints more information about the files while it is
     working out whether or not to transfer them.

zfcget [ -Gt ] FILE1 ...
     As zfget, but if any of the local files exists, and is shorter than
     the corresponding remote file, the command assumes that it is the
     result of a partially completed transfer and attempts to transfer
     the rest of the file.  This is useful on a poor connection which
     keeps failing.

     Note that this requires a commonly implemented, but non-standard,
     version of the FTP protocol, so is not guaranteed to work on all
     servers.

zfgcp [ -Gt ] REMOTE-FILE LOCAL-FILE
zfgcp [ -Gt ] RFILE1 ... LDIR
     This retrieves files from the remote server with arguments behaving
     similarly to the cp command.

     In the first form, copy REMOTE-FILE from the server to the local
     file LOCAL-FILE.

     In the second form, copy all the remote files RFILE1 ... into the
     local directory LDIR retaining the same basenames.  This assumes
     UNIX directory semantics.

Sending files
-------------

zfput [ -r ] FILE1 ...
     Send all the FILE1 ... given separately to the remote server.  If a
     filename contains a `/', the full filename is used locally to find
     the file, but only the basename is used for the remote file name.

     With the option -r, if any of the FILES are directories they are
     sent recursively with all their subdirectories, including files
     beginning with `.'.  This requires that the remote machine
     understand UNIX file semantics, since `/' is used as a directory
     separator.

zfuput [ -vs ] FILE1 ...
     As zfput, but only send files which are newer than their local
     equivalents, or if the remote file does not exist.  The logic is
     the same as for zfuget, but reversed between local and remote
     files.

zfcput FILE1 ...
     As zfput, but if any remote file already exists and is shorter
     than the local equivalent, assume it is the result of an
     incomplete transfer and send the rest of the file to append to the
     existing part.  As the FTP append command is part of the standard
     set, this is in principle more likely to work than zfcget.

zfpcp LOCAL-FILE REMOTE-FILE
zfpcp LFILE1 ... RDIR
     This sends files to the remote server with arguments behaving
     similarly to the cp command.

     With two arguments, copy LOCAL-FILE to the server as REMOTE-FILE.

     With more than two arguments, copy all the local files LFILE1 ...
     into the existing remote directory RDIR retaining the same
     basenames.  This assumes UNIX directory semantics.

     A problem arises if you attempt to use zfpcp LFILE1 RDIR, i.e. the
     second form of copying but with two arguments, as the command has
     no simple way of knowing if RDIR corresponds to a directory or a
     filename.  It attempts to resolve this in various ways.  First, if
     the RDIR argument is `.' or `..' or ends in a slash, it is assumed
     to be a directory.  Secondly, if the operation of copying to a
     remote file in the first form failed, and the remote server sends
     back the expected failure code 553 and a reply including the
     string `Is a directory', then zfpcp will retry using the second
     form.

Closing the connection
----------------------

zfclose
     Close the connection.

Session management
------------------

zfsession [ -lvod ] [ SESSNAME ]
     Allows you to manage multiple FTP sessions at once.  By default,
     connections take place in a session called `default'; by giving the
     command `zfsession SESSNAME' you can change to a new or existing
     session with a name of your choice.  The new session remembers its
     own connection, as well as associated shell parameters, and also
     the host/user parameters set by zfparams.  Hence you can have
     different sessions set up to connect to different hosts, each
     remembering the appropriate host, user and password.

     With no arguments, zfsession prints the name of the current
     session; with the option -l it lists all sessions which currently
     exist, and with the option -v it gives a verbose list showing the
     host and directory for each session, where the current session is
     marked with an asterisk.  With -o, it will switch to the most
     recent previous session.

     With -d, the given session (or else the current one) is removed;
     everything to do with it is completely forgotten.  If it was the
     only session, a new session called `default' is created and made
     current.  It is safest not to delete sessions while background
     commands using zftp are active.

zftransfer SESS1:FILE1 SESS2:FILE2
     Transfer files between two sessions; no local copy is made.  The
     file is read from the session SESS1 as FILE1 and written to session
     SESS2 as file FILE2; FILE1 and FILE2 may be relative to the
     current directories of the session.  Either SESS1 or SESS2 may be
     omitted (though the colon should be retained if there is a
     possibility of a colon appearing in the file name) and defaults to
     the current session; FILE2 may be omitted or may end with a slash,
     in which case the basename of FILE1 will be added.  The sessions
     SESS1 and SESS2 must be distinct.

     The operation is performed using pipes, so it is required that the
     connections still be valid in a subshell, which is not the case
     under versions of some operating systems, presumably due to a
     system bug.

Bookmarks
---------

The two functions zfmark and zfgoto allow you to `bookmark' the present
location (host, user and directory) of the current FTP connection for
later use.  The file to be used for storing and retrieving bookmarks is
given by the parameter $ZFTP_BMFILE; if not set when one of the two
functions is called, it will be set to the file .zfbkmarks in the
directory where your zsh startup files live (usually ~).

zfmark [ BOOKMARK ]
     If given an argument, mark the current host, user and directory
     under the name BOOKMARK for later use by zfgoto.  If there is no
     connection open, use the values for the last connection
     immediately before it was closed; it is an error if there was
     none.  Any existing bookmark under the same name will be silently
     replaced.

     If not given an argument, list the existing bookmarks and the
     points to which they refer in the form USER@HOST:DIRECTORY; this
     is the format in which they are stored, and the file may be edited
     directly.

zfgoto [ -n ] BOOKMARK
     Return to the location given by BOOKMARK, as previously set by
     zfmark.  If the location has user `ftp' or `anonymous', open the
     connection with zfanon, so that no password is required.  If the
     user and host parameters match those stored for the current
     session, if any, those will be used, and again no password is
     required.  Otherwise a password will be prompted for.

     With the option -n, the bookmark is taken to be a nickname stored
     by the ncftp program in its bookmark file, which is assumed to be
     ~/.ncftp/bookmarks.  The function works identically in other ways.
     Note that there is no mechanism for adding or modifying ncftp
     bookmarks from the zftp functions.

Other functions
---------------

Mostly, these functions will not be called directly (apart from
zfinit), but are described here for completeness.  You may wish to
alter zftp_chpwd and zftp_progress, in particular.

zfinit [ -n ]
     As described above, this is used to initialize the zftp function
     system.  The -n option should be used if the zftp command is
     already built into the shell.

zfautocheck [ -dn ]
     This function is called to implement automatic reopening
     behaviour, as described in more detail below.  The options must
     appear in the first argument; -n prevents the command from
     changing to the old directory, while -d prevents it from setting
     the variable do_close, which it otherwise does as a flag for
     automatically closing the connection after a transfer.  The host
     and directory for the last session are stored in the variable
     $zflastsession, but the internal host/user/password parameters
     must also be correctly set.

zfcd_match PREFIX SUFFIX
     This performs matching for completion of remote directory names.
     If the remote server is UNIX, it will attempt to persuade the
     server to list the remote directory with subdirectories marked,
     which usually works but is not guaranteed.  On other hosts it
     simply calls zfget_match and hence completes all files, not just
     directories.  On some systems, directories may not even look like
     filenames.

zfget_match PREFIX SUFFIX
     This performs matching for completion of remote filenames.  It
     caches files for the current directory (only) in the shell
     parameter $zftp_fcache.  It is in the form to be called by the -K
     option of compctl, but also works when called from a widget-style
     completion function with PREFIX and SUFFIX set appropriately.

zfrglob VARNAME
     Perform remote globbing, as describes in more detail below.
     VARNAME is the name of a variable containing the pattern to be
     expanded; if there were any matches, the same variable will be set
     to the expanded set of filenames on return.

zfrtime LFILE RFILE [ TIME ]
     Set the local file LFILE to have the same modification time as the
     remote file RFILE, or the explicit time TIME in FTP format
     CCYYMMDDhhmmSS for the GMT timezone.

     Currently this requires perl version 5 to perform the conversion
     from GMT to local time.  This is unfortunately difficult to do
     using shell code alone.

zftp_chpwd
     This function is called every time a connection is opened, or
     closed, or the remote directory changes.  This version alters the
     title bar of an xterm-compatible or sun-cmd terminal emulator to
     reflect the local and remote hostnames and current directories.
     It works best when combined with the function chpwd.  In
     particular, a function of the form

          chpwd() {
            if [[ -n $ZFTP_USER ]]; then
              zftp_chpwd
            else
              # usual chpwd e.g put host:directory in title bar
            fi
          }

     fits in well.

zftp_progress
     This function shows the status of the transfer.  It will not write
     anything unless the output is going to a terminal; however, if you
     transfer files in the background, you should turn off progress
     reports by hand using `zstyle ':zftp:*' progress none'.  Note also
     that if you alter it, any output _must_ be to standard error, as
     standard output may be a file being received.  The form of the
     progress meter, or whether it is used at all, can be configured
     without altering the function, as described in the next section.

zffcache
     This is used to implement caching of files in the current
     directory for each session separately.  It is used by zfget_match
     and zfrglob.

