home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: mzraly@cs.umb.edu (Michael S Zraly)
- Subject: v26i296: sftp - command line ftp interface, Patch01
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: mzraly@cs.umb.edu (Michael S Zraly)
- Posting-Number: Volume 26, Issue 296
- Archive-Name: sftp/patch01
-
- *** Makefile.orig Fri Jul 16 23:35:20 1993
- --- Makefile Fri Jul 16 23:35:20 1993
- ***************
- *** 1,4 ****
- ! # Makefile
- # Michael S Zraly
- # mzraly@cs.umb.edu
- # 26 July 1992
- --- 1,4 ----
- ! # sftp Makefile
- # Michael S Zraly
- # mzraly@cs.umb.edu
- # 26 July 1992
- *** README.orig Fri Jul 16 23:35:20 1993
- --- README Fri Jul 16 23:35:20 1993
- ***************
- *** 1,4 ****
- ! README
- Michael S Zraly
- mzraly@cs.umb.edu
- 26 July 1992
- --- 1,4 ----
- ! sftp README
- Michael S Zraly
- mzraly@cs.umb.edu
- 26 July 1992
- ***************
- *** 13,22 ****
- REQUIREMENTS
-
- No special permissions are required. The only non-standard command
- ! that sftp uses is getopts(1). It is available by anonymous FTP
- ! from a number of sites; let archie(1) be your guide. The source for
- ! getopts is in perl.
-
- INSTALLATION
-
- Type "make install". The only "compiling" necessary is the formatting
- --- 13,38 ----
- REQUIREMENTS
-
- No special permissions are required. The only non-standard command
- ! that sftp uses is getopts(1). If you do not have getopts built into
- ! your version of /bin/sh, you have two options:
-
- + (1) change the first line in sftp from "#! /bin/sh"
- + to "#! /bin/ksh" or "#! /bin/bash" or whatever
- + the paths are on your system for the Korn shell
- + and the GNU people's Bourne-again shell. These
- + shells both have getopts built into them.
- +
- + (2) Get rmgetopts, which I hope will be distributed
- + over comp.sources.unix soon. If it isn't send me
- + mail at mzraly@cs.umb.edu and I'll send you a copy.
- + rmgetopts converts shell scripts using getopts to
- + parse command line options into ones that don't.
- + Once rmgetopts is in place, just type
- +
- + % mv sftp sftp.orig
- + % rmgetopts sftp.orig > sftp
- + % chmod +x sftp
- +
- INSTALLATION
-
- Type "make install". The only "compiling" necessary is the formatting
- ***************
- *** 31,34 ****
- --- 47,59 ----
- Send them (and fixes, if you have them) to me at:
-
- mzraly@cs.umb.edu
- +
- + HISTORY
- +
- + The first version of sftp was submitted to comp.sources.unix in July
- + of 1992 and distributed in July of 1993. At the time I thought that
- + getopts was a program separate from the shell, not realizing that the
- + getopts sources I had seen on the net were strictly in and for perl.
- +
- + The second version was created in July 1993 to tighten up the code.
-
- *** sftp.orig Fri Jul 16 23:35:20 1993
- --- sftp Fri Jul 16 23:35:20 1993
- ***************
- *** 1,4 ****
- ! #! /bin/sh
- #
- # sftp -- "surgical" FTP
- #
- --- 1,4 ----
- ! #!/bin/sh
- #
- # sftp -- "surgical" FTP
- #
- ***************
- *** 8,259 ****
- #
- # Based loosely on getfile, written by John Granrose
- # for his anonymous FTP archive at pilot.njin.net.
- -
- - cmd=
- - dbg=false
- - use=false
- - ver=false
- - bin=false
- - hash=false
- - mac=
- - dir=
- - fil=
- - key=
- - sub=
- -
- - usage='-(g|l|m) [-duvbh] (site dir | [-f file] -k key [-s subdir]) file[s]'
- -
- - prog=`basename $0`
- -
- - USAGE="usage: $prog $usage"
- -
- #
- ! # Set initial value for fil
- #
- !
- ! if test -n "$FTPKEYS"
- ! then
- ! fil=$FTPKEYS
- ! elif test -r .ftpkeys
- ! then
- ! fil=.ftpkeys
- ! elif test -r $HOME/.ftpkeys
- ! then
- ! fil=$HOME/.ftpkeys
- ! fi
- !
- #
- ! # Parse options
- #
- !
- ! while getopts glmduvbhf:k:s: c
- ! do
- ! case $c in
- ! g) if test -n "$cmd"
- ! then
- ! echo option -g 1>&2
- ! echo $USAGE 1>&2
- ! exit 1
- ! fi
- ! cmd=get
- ! ;;
- ! l) if test -n "$cmd"
- ! then
- ! echo option -l 1>&2
- ! echo $USAGE 1>&2
- ! exit 1
- ! fi
- ! cmd=ls
- ! ;;
- ! m) if test -n "$cmd"
- ! then
- ! echo option -m 1>&2
- ! echo $USAGE 1>&2
- ! exit 1
- ! fi
- ! cmd=mget
- ! ;;
- ! d) dbg=true
- ! ;;
- ! u) use=true
- ! ;;
- ! v) ver=true
- ! ;;
- ! b) bin=true
- ! ;;
- ! h) hash=true
- ! ;;
- ! f) fil=$OPTARG
- ! ;;
- ! k) key=$OPTARG
- ! ;;
- ! s) sub=$OPTARG
- ! ;;
- ! *) echo option -$c 1>&2
- ! echo $USAGE 1>&2
- ! exit 1
- ! ;;
- ! esac
- ! done
- !
- ! shift `expr $OPTIND - 1`
- !
- #
- ! # Set cmd, fil variables appropriately
- #
- !
- ! if test -z "$cmd"
- ! then
- ! cmd=ls
- ! fi
- !
- ! if test -z "$key" -o -z "$fil"
- ! then
- ! fil=/dev/null
- ! fi
- !
- #
- ! # Now to determine mac, dir variables
- #
-
- ! if test -z "$key"
- ! then
- ! if test "$cmd" = "ls"
- ! then
- ! min=2
- ! else
- ! min=3
- ! fi
- !
- ! if test "$#" -lt "$min"
- ! then
- ! echo too few args 1>&2
- ! echo $USAGE 1>&2
- ! exit 1
- ! else
- ! mac=$1
- ! dir=$2
- ! shift
- ! shift
- ! fi
- ! else
- ! #
- ! # Here we need to read $fil and look for $key to get $mac. $dir
- ! #
- ! str=`grep "^$key[ ]" $fil`
- ! mac=`echo "$str" | awk '{ print $2 }'`
- ! dir=`echo "$str" | awk '{ print $3 }'`
- ! fi
-
- ! if test -z "$mac"
- ! then
- ! echo machine not set 1>&2
- ! echo $prog: ERROR 1>&2
- ! dbg=true
- ! fi
-
- ! #
- ! # Take care of possible subdirectory
- ! #
-
- ! if test -n "$sub"
- ! then
- ! dir=$dir/$sub
- ! fi
-
- ! #
- ! # Now check for debugging option
- ! #
-
- ! if test $dbg = "true"
- then
- ! echo "cmd = \"$cmd\""
- ! echo "dbg = \"$dbg\""
- ! echo "use = \"$use\""
- ! echo "ver = \"$ver\""
- ! echo "bin = \"$bin\""
- ! echo "hash = \"$hash\""
- ! echo "mac = \"$mac\""
- ! echo "dir = \"$dir\""
- ! echo "fil = \"$fil\""
- ! echo "key = \"$key\""
- ! echo "sub = \"$sub\""
- ! exit 0
- fi
-
- ! #
- ! # Set arguments to FTP command
- ! #
-
- ! if test "$use" = "false"
- ! then
- ! optn=-n
- ! fi
-
- ! if test "$ver" = "true"
- ! then
- ! optv=-v
- ! fi
-
- ! #
- ! # Now for the actual FTP'ing
- ! #
-
- ! (
- ! #
- ! # If not using .netrc file, assume anonymous login
- ! #
- ! if test "$use" = "false"
- ! then
- ! echo user anonymous $USER@$HOST
- ! fi
- ! #
- ! # cd to base directory
- ! #
- ! if test -n "$dir"
- ! then
- ! echo cd $dir
- ! fi
- ! #
- ! # take care of binary, hash commands if needed
- ! #
- ! if test "$bin" = "true"
- ! then
- ! echo binary
- ! fi
- ! if test "$hash" = "true"
- ! then
- ! echo hash
- ! fi
- ! #
- ! # execute ftp command
- ! #
- ! case "$cmd" in
- ! ls) if test "$#" -gt 0
- ! then
- ! for n do
- ! echo ls $n
- ! done
- ! else
- ! echo ls
- ! fi
- ! ;;
- ! get) echo get $1 $2
- ;;
- ! mget) for n do
- ! echo mget $n
- ! done
- ;;
- ! *) echo $prog: Invalid ftp command $cmd 1>&2
- ;;
- esac
- ! #
- ! # all done
- ! #
- echo bye
- ! ) | ftp -i $optn $optv $mac
-
- - #
- - # Exit with status of FTP command
- - #
- exit $?
- --- 8,185 ----
- #
- # Based loosely on getfile, written by John Granrose
- # for his anonymous FTP archive at pilot.njin.net.
- #
- ! # Michael S Zraly
- ! # mzraly@cs.umb.edu
- ! # 8 July 1993
- #
- ! # Oops! Not all versions of sh have getopts.
- ! # Rewrite eliminates call to getopts and parses
- ! # arguments by hand (yuck!)
- #
- ! # Actually we'll release the source using getopts
- ! # along with a separate program, rmgetopts, that
- ! # will convert getopts-style option parsing to the
- ! # more portable hand-parsing equivalent.
- #
- ! # Might as well tighten the code up while we're at it:
- #
- ! # (1) Move consistency tests OUT of ftp input subshell,
- ! # so that we know before invoking ftp whether or not
- ! # (for instance) $command is bogus.
- #
- ! # (2) Wherever possible, replace invocations of the program
- ! # 'test' with the shell built-in 'case'. In general,
- ! #
- ! # if test -z "$foo"; then case "$foo" in
- ! # ... ===> "") ...;;
- ! # fi esac
- ! #
- ! # and
- ! #
- ! # if test -n "$foo"; then case "$foo" in
- ! # ... ===> ?*) ...;;
- ! # fi esac
- ! #
- ! # Why? Because 'case' is a shell built-in whose execution
- ! # does not require the shell to exec another process, while
- ! # test is a separate program. Typically, then, a 'test' will
- ! # take longer than a 'case'.
- #
- ! # (3) Improve error checking and messages.
- #
- + # (4) Generally reformat for better readability.
-
- ! prog=`basename $0`
- ! usage='[-glmbhuv] [-s subdir] (host [dir] | [-f file] -k key) file[s]'
-
- ! USAGE="usage: $prog $usage"
-
- ! # Initialize variables
-
- ! command=ls # ftp command to give
- ! binary= # binary command, if to be given
- ! hash= # hash command, if to be given
- ! usenetrc=n # use .netrc ? opposite of ftp's -n flag
- ! verbose=n # verbose connection ? same as ftp's -v flag
- ! topdir= # main directory in which ftp commands are to be given
- ! subdir= # subdirectory of topdir in which ftp commands are to be given
- ! host= # host on which ftp commands are to be given
- ! ftpkeys= # file containing references to commonly used hosts
- ! key= # key used to search ftpkeys file
-
- ! # Set initial value for ftpkeys
-
- ! if test -n "$FTPKEYS"
- ! then
- ! ftpkeys=$FTPKEYS
- ! elif test -r ".ftpkeys"
- ! then
- ! ftpkeys=.ftpkeys
- ! elif test -r "$HOME/.ftpkeys"
- then
- ! ftpkeys=$HOME/.ftpkeys
- fi
-
- ! # Parse options
-
- ! while getopts glmbhuvf:k:s: c
- ! do
- ! case "$c" in
- ! g) command=get;;
- ! l) command=ls;;
- ! m) command=mget;;
- ! u) usenetrc=y;;
- ! v) verbose=y;;
- ! b) binary=binary;;
- ! h) hash=hash;;
- ! f) ftpkeys=$OPTARG;;
- ! k) key=$OPTARG;;
- ! s) subdir=$OPTARG;;
- ! *) echo "$USAGE" 1>&2; exit 1;;
- ! esac
- ! done
-
- ! shift `expr $OPTIND - 1`
-
- ! # Check variable consistency
-
- ! case "$ftpkeys" in
- ! "") ftpkeys=/dev/null;;
- ! esac
- !
- ! case "$key" in
- ! "") ftpkeys=/dev/null
- ! case "$#" in
- ! 0) echo "$prog: no host on command line" 1>&2
- ! echo "$USAGE" 1>&2; exit 1
- ;;
- ! 1) host=$1; shift;;
- ! *) host=$1; topdir=$2; shift 2;;
- ! esac
- ! ;;
- ! *) str=`grep -e "^$key[ ]" $ftpkeys`
- ! case "$str" in
- ! "") echo "$prog: key '$key' not in file '$ftpkeys'" 1>&2; exit 1;;
- ! esac
- ! host=`echo "$str" | awk '{ print $2 }'`
- ! case "$host" in
- ! "") echo "$prog: host not found in key entry '$str'" 1>&2; exit 1;;
- ! esac
- ! topdir=`echo "$str" | awk '{ print $3 }'`
- ! ;;
- ! esac
- !
- ! case "$command" in
- ! ls) ;;
- ! get) case "$#" in
- ! 1|2) ;;
- ! *) echo "$prog: too many args for get command ($*)" 1>&2
- ! echo "$USAGE" 1>&2; exit 1
- ;;
- ! esac
- ! ;;
- ! mget) case "$1" in
- ! "") echo "$prog: too few args for mget command ($*)" 1>&2
- ! echo "$USAGE" 1>&2; exit 1
- ;;
- esac
- ! ;;
- ! *) echo "$prog: command not set -- this should never happen" 1>&2
- ! echo "$USAGE" 1>&2; exit 1
- ! ;;
- ! esac
- !
- ! # Set arguments to FTP command
- !
- ! case "$usenetrc" in
- ! n) optn=-n;;
- ! esac
- !
- ! case "$verbose" in
- ! y) optv=-v;;
- ! esac
- !
- ! # Do the FTP thing
- !
- ! (
- ! case "$usenetrc" in
- ! n) echo user anonymous $USER@$HOST;;
- ! esac
- !
- ! case "$topdir" in
- ! ?*) echo cd $topdir;;
- ! esac
- !
- ! case "$subdir" in
- ! ?*) echo cd $subdir;;
- ! esac
- !
- ! echo $binary
- ! echo $hash
- ! echo $command $*
- echo bye
- ! ) | ftp -i $optn $optv $host
-
- exit $?
- +
- *** sftp.1.orig Fri Jul 16 23:35:20 1993
- --- sftp.1 Fri Jul 16 23:35:20 1993
- ***************
- *** 1,42 ****
- ! .\" man page
- .\" Michael S Zraly
- .\" mzraly@cs.umb.edu
- ! .\" 26 July 1992
- .\"
- .TH SFTP 1 "July 25, 1992"
- .SH NAME
- ! sftp \- "surgical" FTP interface
- .SH SYNOPSIS
- ! \fBsftp \-g\fP [\fB\-duvbh\fP]
- ! machine dir local [remote]
- ! .br
- ! \fBsftp \-g\fP [\fB\-duvbh\fP]
- ! [\fB\-f\fPfile] \fB\-k\fPkey \fB\-s\fPsubdir local [remote]
- ! .br
- ! \fBsftp \-l\fP [\fB\-duvbh\fP]
- ! machine dir [files]
- ! .br
- ! \fBsftp \-l\fP [\fB\-duvbh\fP]
- ! [\fB\-f\fPfile] \fB\-k\fPkey \fB\-s\fPsubdir [files]
- ! .br
- ! \fBsftp \-m\fP [\fB\-duvbh\fP]
- ! machine dir file[s]
- ! .br
- ! \fBsftp \-m\fP [\fB\-duvbh\fP]
- ! [\fB\-f\fPfile] \fB\-k\fPkey \fB\-s\fPsubdir file[s]
- ! .br
- .SH DESCRIPTION
- ! .PP
- .I sftp
- is a front end for the get, ls, and mget commands of
- .IR ftp (1).
- It provides the means for a user to execute a ``surgical strike''
- into an FTP site; that is, the FTP session is quick, direct, and
- ! effective. Little time is wasted.
- ! Note that this command is very useful in conjunction with the
- ! .IR archie (1)
- ! client.
- ! .PP
- Which command is used depends on which of the options
- .BR \-g ,
- .BR \-l ,
- --- 1,35 ----
- ! .\" sftp manual-page
- .\" Michael S Zraly
- .\" mzraly@cs.umb.edu
- ! .\" 26 July 1992 original
- ! .\" 16 July 1993 updated
- .\"
- .TH SFTP 1 "July 25, 1992"
- .SH NAME
- ! sftp \- ``surgical'' FTP interface
- .SH SYNOPSIS
- ! .B sftp
- ! [
- ! .B \-glmbhuv
- ! ]
- ! [
- ! .BI \-s " sub"
- ! ]
- ! (host [dir] |
- ! [
- ! .BI \-f " file"
- ! ]
- ! .BI \-k " key)"
- ! file...
- .SH DESCRIPTION
- ! .LP
- .I sftp
- is a front end for the get, ls, and mget commands of
- .IR ftp (1).
- It provides the means for a user to execute a ``surgical strike''
- into an FTP site; that is, the FTP session is quick, direct, and
- ! effective.
- ! .LP
- Which command is used depends on which of the options
- .BR \-g ,
- .BR \-l ,
- ***************
- *** 54,70 ****
- file which contains lines of the form:
- .RS
- .sp
- ! keyword machine directory
- .sp
- .RE
- The
- .I ftpkeys
- ! file may be specified by the environment variable
- ! ``FTPKEYS''. If this variable is not set,
- ! the current directory will be searched for a file
- ! named ``.ftpkeys''; finally, if there is no such
- ! file in the current directory, the user's home
- ! directory will be searched for a ``.ftpkeys'' file.
- .SH OPTIONS
- .TP
- .B \-g
- --- 47,62 ----
- file which contains lines of the form:
- .RS
- .sp
- ! keyword machine [directory]
- .sp
- .RE
- The
- .I ftpkeys
- ! file may be specified by the environment variable ``FTPKEYS''.
- ! If this variable is not set,
- ! the current directory will be searched for a file named ``.ftpkeys'';
- ! if there is no such file in the current directory,
- ! the user's home directory will be searched for a ``.ftpkeys'' file.
- .SH OPTIONS
- .TP
- .B \-g
- ***************
- *** 82,90 ****
- .I mget
- command.
- .TP
- ! .B \-d
- ! Rather than executing FTP command,
- ! print debugging information.
- .TP
- .B \-u
- Rather than FTP'ing anonymously, use the
- --- 74,89 ----
- .I mget
- command.
- .TP
- ! .B \-b
- ! Before file transfer, give the FTP
- ! .I binary
- ! command.
- ! Some FTP daemons automatically issue this command.
- ! .TP
- ! .B \-h
- ! Before file transfer, give the FTP
- ! .I hash
- ! command.
- .TP
- .B \-u
- Rather than FTP'ing anonymously, use the
- ***************
- *** 99,178 ****
- .IR ftp (1)
- command, so that the session is printed to the terminal.
- .TP
- ! .B \-b
- ! Before file transfer, give the FTP
- ! .I binary
- ! command. Note that some FTP daemons automatically issue this command.
- ! .TP
- ! .B \-h
- ! Before file transfer, give the FTP
- ! .I hash
- ! command.
- ! .TP
- ! .BR \-f file
- Use
- .I file
- in place of ``$FTPKEYS'' or ``./.ftpkeys'' or ``~/.ftpkeys''
- (see above).
- .TP
- ! .BR \-k key
- ! Use key to search for appropriate entry in
- .I ftpkeys
- file to determine target machine and directory.
- .TP
- ! .BR \-s sub
- ! Append
- ! .I sub
- ! to target directory. Used mainly with the
- .B \-k
- option, but allowed without it.
- .SH EXAMPLES
- ! .PP
- ! To list the top-level at ftp.uu.net:
- .RS
- .sp
- sftp ftp.uu.net /
- .RE
- ! .PP
- To get the shell script from which this command is ultimately derived:
- .RS
- .sp
- sftp -g pilot.njin.net pub/ftp-list getfile
- .RE
- ! .PP
- To view that file without actually copying it to the local machine:
- .RS
- .sp
- sftp -g pilot.njin.net pub/ftp-list getfile "|cat"
- .RE
- ! .PP
- ! To read that file through a more complicated command,
- or any command with spaces in it, nest quotation marks thusly:
- .RS
- .sp
- ! sftp -g pilot.njin.net pub/ftp-list getfile '"|more -c"'
- ! .RE
- ! .PP
- ! To get the index for comp.sources.misc:
- ! .RS
- ! .sp
- ! sftp -g ftp.uu.net usenet/comp.sources.misc index
- .RE
- ! .PP
- ! To get all the compressed files from that directory:
- ! (Note that single quotes are used to prevent expansion
- ! of the shell metacharacter ``*'').
- .RS
- .sp
- sftp -m ftp.uu.net usenet/comp.sources.misc '*.Z'
- .RE
- ! .PP
- Assume there is an entry in the ftpkeys file:
- .RS
- .sp
- CSG ftp.uu.net usenet/comp.sources.games
- .RE
- ! .PP
- Now to get the sources for the
- .IR rogue (6)
- clone:
- --- 98,169 ----
- .IR ftp (1)
- command, so that the session is printed to the terminal.
- .TP
- ! .BI \-f file
- Use
- .I file
- in place of ``$FTPKEYS'' or ``./.ftpkeys'' or ``~/.ftpkeys''
- (see above).
- .TP
- ! .BI \-k key
- ! Use
- ! .I key
- ! to search for appropriate entry in
- .I ftpkeys
- file to determine target machine and directory.
- .TP
- ! .BI \-s sub
- ! After changing directory to
- ! .IR dir ,
- ! as specified on the command line,
- ! change directory again to
- ! .IR sub .
- ! Used mainly with the
- .B \-k
- option, but allowed without it.
- .SH EXAMPLES
- ! .LP
- ! Three ways to list the top-level directory at ftp.uu.net:
- .RS
- .sp
- + sftp ftp.uu.net
- + .br
- sftp ftp.uu.net /
- + .br
- + sftp -s / ftp.uu.net
- .RE
- ! .LP
- To get the shell script from which this command is ultimately derived:
- .RS
- .sp
- sftp -g pilot.njin.net pub/ftp-list getfile
- .RE
- ! .LP
- To view that file without actually copying it to the local machine:
- .RS
- .sp
- sftp -g pilot.njin.net pub/ftp-list getfile "|cat"
- .RE
- ! .LP
- ! To read a file through a more complicated command,
- or any command with spaces in it, nest quotation marks thusly:
- .RS
- .sp
- ! sftp -g world.std.com / README '"|more -c"'
- .RE
- ! .LP
- ! To get all the compressed files from the comp.sources.misc directory:
- ! (Single quotes are used to prevent shell expansion of ``*'').
- .RS
- .sp
- sftp -m ftp.uu.net usenet/comp.sources.misc '*.Z'
- .RE
- ! .LP
- Assume there is an entry in the ftpkeys file:
- .RS
- .sp
- CSG ftp.uu.net usenet/comp.sources.games
- .RE
- ! .LP
- Now to get the sources for the
- .IR rogue (6)
- clone:
- ***************
- *** 196,212 ****
- directory\-entries.
- See the DESCRIPTION section above for more information.
- .SH "SEE ALSO"
- ! .PP
- ! .IR archie (1),
- ! .IR awk (1),
- .IR ftp (1),
- ! .IR getopts (1),
- ! .IR grep (1),
- ! .IR sh (1),
- ! .IR test (1).
- .SH BUGS
- ! .PP
- The keyword lookup scheme could be more fully developed.
- .SH AUTHOR
- ! .PP
- Michael S Zraly (mzraly@cs.umb.edu)
- --- 187,198 ----
- directory\-entries.
- See the DESCRIPTION section above for more information.
- .SH "SEE ALSO"
- ! .LP
- .IR ftp (1),
- ! .IR sh (1).
- .SH BUGS
- ! .LP
- The keyword lookup scheme could be more fully developed.
- .SH AUTHOR
- ! .LP
- Michael S Zraly (mzraly@cs.umb.edu)
-