home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: mzraly@cs.umb.edu (Michael S Zraly)
- Subject: v26i279: sftp - command line ftp interface, Part01/01
- 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 279
- Archive-Name: sftp/part01
-
- Sftp is a shell script that allows a user to quickly perform the most
- common ftp activities -- listing files and retrieving files -- with a
- minimum of fuss and minimum time connected to busy FTP sites.
-
- mzraly@cs.umb.edu (Michael S Zraly)
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: MANIFEST Makefile README sftp sftp.1
- # Wrapped by vixie@gw.home.vix.com on Sat Jul 3 13:06:41 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(269 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1 This shipping list
- X Makefile 1
- X README 1
- X sftp 1
- X sftp.1 1
- END_OF_FILE
- if test 269 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(594 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X# Makefile
- X# Michael S Zraly
- X# mzraly@cs.umb.edu
- X# 26 July 1992
- X
- XPROG= sftp
- X
- XBIN= /usr/local/bin
- XMAN= /usr/local/man
- X
- XFILES= Makefile README $(PROG) $(PROG).1
- X
- Xall: $(PROG).man $(PROG).1 $(PROG)
- X
- Xinstall: all
- X cp $(PROG) $(BIN) && chmod 755 $(BIN)/$(PROG)
- X cp $(PROG).1 $(MAN)/man1/$(PROG).1 && chmod 644 $(MAN)/man1/$(PROG).1
- X cp $(PROG).man $(MAN)/cat1/$(PROG).1 && chmod 644 $(MAN)/cat1/$(PROG).1
- X
- Xclean:
- X rm -f $(PROG).man $(PROG).tar.Z
- X
- X$(PROG).man: $(PROG).1
- X nroff -man $(PROG).1 > $(PROG).man
- X
- Xdist: $(PROG).tar.Z
- X
- X$(PROG).tar.Z: $(FILES)
- X tar cvf - $(FILES) | compress > $(PROG).tar.Z
- END_OF_FILE
- if test 594 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(959 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XREADME
- XMichael S Zraly
- Xmzraly@cs.umb.edu
- X26 July 1992
- X
- X
- XDESCRIPTION
- X
- XSftp is a shell script that allows a user to quickly perform the most
- Xcommon ftp activities -- listing files and retrieving files -- with a
- Xminimum of fuss and minimum time connected to busy FTP sites.
- X
- XREQUIREMENTS
- X
- XNo special permissions are required. The only non-standard command
- Xthat sftp uses is getopts(1). It is available by anonymous FTP
- Xfrom a number of sites; let archie(1) be your guide. The source for
- Xgetopts is in perl.
- X
- XINSTALLATION
- X
- XType "make install". The only "compiling" necessary is the formatting
- Xof the manual page; "make install" merely formats the manual page with
- Xnroff(1) and copies the manual pages and shell script into the
- Xappropriate directories. You'll have to update the whatis(1) database
- Xby hand, though, since there are too many variations for me to worry
- Xabout.
- X
- XBUG REPORTS
- X
- XSend them (and fixes, if you have them) to me at:
- X
- X mzraly@cs.umb.edu
- X
- END_OF_FILE
- if test 959 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'sftp' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'sftp'\"
- else
- echo shar: Extracting \"'sftp'\" \(3169 characters\)
- sed "s/^X//" >'sftp' <<'END_OF_FILE'
- X#! /bin/sh
- X#
- X# sftp -- "surgical" FTP
- X#
- X# Michael S Zraly
- X# mzraly@cs.umb.edu
- X# 26 July 1992
- X#
- X# Based loosely on getfile, written by John Granrose
- X# for his anonymous FTP archive at pilot.njin.net.
- X
- Xcmd=
- Xdbg=false
- Xuse=false
- Xver=false
- Xbin=false
- Xhash=false
- Xmac=
- Xdir=
- Xfil=
- Xkey=
- Xsub=
- X
- Xusage='-(g|l|m) [-duvbh] (site dir | [-f file] -k key [-s subdir]) file[s]'
- X
- Xprog=`basename $0`
- X
- XUSAGE="usage: $prog $usage"
- X
- X#
- X# Set initial value for fil
- X#
- X
- Xif test -n "$FTPKEYS"
- Xthen
- X fil=$FTPKEYS
- Xelif test -r .ftpkeys
- Xthen
- X fil=.ftpkeys
- Xelif test -r $HOME/.ftpkeys
- Xthen
- X fil=$HOME/.ftpkeys
- Xfi
- X
- X#
- X# Parse options
- X#
- X
- Xwhile getopts glmduvbhf:k:s: c
- Xdo
- X case $c in
- X g) if test -n "$cmd"
- X then
- X echo option -g 1>&2
- X echo $USAGE 1>&2
- X exit 1
- X fi
- X cmd=get
- X ;;
- X l) if test -n "$cmd"
- X then
- X echo option -l 1>&2
- X echo $USAGE 1>&2
- X exit 1
- X fi
- X cmd=ls
- X ;;
- X m) if test -n "$cmd"
- X then
- X echo option -m 1>&2
- X echo $USAGE 1>&2
- X exit 1
- X fi
- X cmd=mget
- X ;;
- X d) dbg=true
- X ;;
- X u) use=true
- X ;;
- X v) ver=true
- X ;;
- X b) bin=true
- X ;;
- X h) hash=true
- X ;;
- X f) fil=$OPTARG
- X ;;
- X k) key=$OPTARG
- X ;;
- X s) sub=$OPTARG
- X ;;
- X *) echo option -$c 1>&2
- X echo $USAGE 1>&2
- X exit 1
- X ;;
- X esac
- Xdone
- X
- Xshift `expr $OPTIND - 1`
- X
- X#
- X# Set cmd, fil variables appropriately
- X#
- X
- Xif test -z "$cmd"
- Xthen
- X cmd=ls
- Xfi
- X
- Xif test -z "$key" -o -z "$fil"
- Xthen
- X fil=/dev/null
- Xfi
- X
- X#
- X# Now to determine mac, dir variables
- X#
- X
- Xif test -z "$key"
- Xthen
- X if test "$cmd" = "ls"
- X then
- X min=2
- X else
- X min=3
- X fi
- X
- X if test "$#" -lt "$min"
- X then
- X echo too few args 1>&2
- X echo $USAGE 1>&2
- X exit 1
- X else
- X mac=$1
- X dir=$2
- X shift
- X shift
- X fi
- Xelse
- X #
- X # Here we need to read $fil and look for $key to get $mac. $dir
- X #
- X str=`grep "^$key[ ]" $fil`
- X mac=`echo "$str" | awk '{ print $2 }'`
- X dir=`echo "$str" | awk '{ print $3 }'`
- Xfi
- X
- Xif test -z "$mac"
- Xthen
- X echo machine not set 1>&2
- X echo $prog: ERROR 1>&2
- X dbg=true
- Xfi
- X
- X#
- X# Take care of possible subdirectory
- X#
- X
- Xif test -n "$sub"
- Xthen
- X dir=$dir/$sub
- Xfi
- X
- X#
- X# Now check for debugging option
- X#
- X
- Xif test $dbg = "true"
- Xthen
- X echo "cmd = \"$cmd\""
- X echo "dbg = \"$dbg\""
- X echo "use = \"$use\""
- X echo "ver = \"$ver\""
- X echo "bin = \"$bin\""
- X echo "hash = \"$hash\""
- X echo "mac = \"$mac\""
- X echo "dir = \"$dir\""
- X echo "fil = \"$fil\""
- X echo "key = \"$key\""
- X echo "sub = \"$sub\""
- X exit 0
- Xfi
- X
- X#
- X# Set arguments to FTP command
- X#
- X
- Xif test "$use" = "false"
- Xthen
- X optn=-n
- Xfi
- X
- Xif test "$ver" = "true"
- Xthen
- X optv=-v
- Xfi
- X
- X#
- X# Now for the actual FTP'ing
- X#
- X
- X(
- X #
- X # If not using .netrc file, assume anonymous login
- X #
- X if test "$use" = "false"
- X then
- X echo user anonymous $USER@$HOST
- X fi
- X #
- X # cd to base directory
- X #
- X if test -n "$dir"
- X then
- X echo cd $dir
- X fi
- X #
- X # take care of binary, hash commands if needed
- X #
- X if test "$bin" = "true"
- X then
- X echo binary
- X fi
- X if test "$hash" = "true"
- X then
- X echo hash
- X fi
- X #
- X # execute ftp command
- X #
- X case "$cmd" in
- X ls) if test "$#" -gt 0
- X then
- X for n do
- X echo ls $n
- X done
- X else
- X echo ls
- X fi
- X ;;
- X get) echo get $1 $2
- X ;;
- X mget) for n do
- X echo mget $n
- X done
- X ;;
- X *) echo $prog: Invalid ftp command $cmd 1>&2
- X ;;
- X esac
- X #
- X # all done
- X #
- X echo bye
- X) | ftp -i $optn $optv $mac
- X
- X#
- X# Exit with status of FTP command
- X#
- Xexit $?
- END_OF_FILE
- if test 3169 -ne `wc -c <'sftp'`; then
- echo shar: \"'sftp'\" unpacked with wrong size!
- fi
- # end of 'sftp'
- fi
- if test -f 'sftp.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'sftp.1'\"
- else
- echo shar: Extracting \"'sftp.1'\" \(4190 characters\)
- sed "s/^X//" >'sftp.1' <<'END_OF_FILE'
- X.\" man page
- X.\" Michael S Zraly
- X.\" mzraly@cs.umb.edu
- X.\" 26 July 1992
- X.\"
- X.TH SFTP 1 "July 25, 1992"
- X.SH NAME
- Xsftp \- "surgical" FTP interface
- X.SH SYNOPSIS
- X\fBsftp \-g\fP [\fB\-duvbh\fP]
- Xmachine dir local [remote]
- X.br
- X\fBsftp \-g\fP [\fB\-duvbh\fP]
- X[\fB\-f\fPfile] \fB\-k\fPkey \fB\-s\fPsubdir local [remote]
- X.br
- X\fBsftp \-l\fP [\fB\-duvbh\fP]
- Xmachine dir [files]
- X.br
- X\fBsftp \-l\fP [\fB\-duvbh\fP]
- X[\fB\-f\fPfile] \fB\-k\fPkey \fB\-s\fPsubdir [files]
- X.br
- X\fBsftp \-m\fP [\fB\-duvbh\fP]
- Xmachine dir file[s]
- X.br
- X\fBsftp \-m\fP [\fB\-duvbh\fP]
- X[\fB\-f\fPfile] \fB\-k\fPkey \fB\-s\fPsubdir file[s]
- X.br
- X.SH DESCRIPTION
- X.PP
- X.I sftp
- Xis a front end for the get, ls, and mget commands of
- X.IR ftp (1).
- XIt provides the means for a user to execute a ``surgical strike''
- Xinto an FTP site; that is, the FTP session is quick, direct, and
- Xeffective. Little time is wasted.
- XNote that this command is very useful in conjunction with the
- X.IR archie (1)
- Xclient.
- X.PP
- XWhich command is used depends on which of the options
- X.BR \-g ,
- X.BR \-l ,
- Xor
- X.B \-m
- Xis given.
- XIn each case the user may specify the target machine and directory
- Xeither directly on the command line, or by specifying a
- X.I keyword
- X(with the
- X.B \-k
- Xoption)
- Xthat refers to an entry in a
- X.I ftpkeys
- Xfile which contains lines of the form:
- X.RS
- X.sp
- Xkeyword machine directory
- X.sp
- X.RE
- XThe
- X.I ftpkeys
- Xfile may be specified by the environment variable
- X``FTPKEYS''. If this variable is not set,
- Xthe current directory will be searched for a file
- Xnamed ``.ftpkeys''; finally, if there is no such
- Xfile in the current directory, the user's home
- Xdirectory will be searched for a ``.ftpkeys'' file.
- X.SH OPTIONS
- X.TP
- X.B \-g
- XUse the FTP
- X.I get
- Xcommand.
- X.TP
- X.B \-l
- XUse the FTP
- X.I ls
- Xcommand.
- X.TP
- X.B \-m
- XUse the FTP
- X.I mget
- Xcommand.
- X.TP
- X.B \-d
- XRather than executing FTP command,
- Xprint debugging information.
- X.TP
- X.B \-u
- XRather than FTP'ing anonymously, use the
- X.I \.netrc
- Xfile (see
- X.IR ftp (1)).
- X.TP
- X.B \-v
- XPass the
- X.B \-v
- Xoption to the
- X.IR ftp (1)
- Xcommand, so that the session is printed to the terminal.
- X.TP
- X.B \-b
- XBefore file transfer, give the FTP
- X.I binary
- Xcommand. Note that some FTP daemons automatically issue this command.
- X.TP
- X.B \-h
- XBefore file transfer, give the FTP
- X.I hash
- Xcommand.
- X.TP
- X.BR \-f file
- XUse
- X.I file
- Xin place of ``$FTPKEYS'' or ``./.ftpkeys'' or ``~/.ftpkeys''
- X(see above).
- X.TP
- X.BR \-k key
- XUse key to search for appropriate entry in
- X.I ftpkeys
- Xfile to determine target machine and directory.
- X.TP
- X.BR \-s sub
- XAppend
- X.I sub
- Xto target directory. Used mainly with the
- X.B \-k
- Xoption, but allowed without it.
- X.SH EXAMPLES
- X.PP
- XTo list the top-level at ftp.uu.net:
- X.RS
- X.sp
- Xsftp ftp.uu.net /
- X.RE
- X.PP
- XTo get the shell script from which this command is ultimately derived:
- X.RS
- X.sp
- Xsftp -g pilot.njin.net pub/ftp-list getfile
- X.RE
- X.PP
- XTo view that file without actually copying it to the local machine:
- X.RS
- X.sp
- Xsftp -g pilot.njin.net pub/ftp-list getfile "|cat"
- X.RE
- X.PP
- XTo read that file through a more complicated command,
- Xor any command with spaces in it, nest quotation marks thusly:
- X.RS
- X.sp
- Xsftp -g pilot.njin.net pub/ftp-list getfile '"|more -c"'
- X.RE
- X.PP
- XTo get the index for comp.sources.misc:
- X.RS
- X.sp
- Xsftp -g ftp.uu.net usenet/comp.sources.misc index
- X.RE
- X.PP
- XTo get all the compressed files from that directory:
- X(Note that single quotes are used to prevent expansion
- Xof the shell metacharacter ``*'').
- X.RS
- X.sp
- Xsftp -m ftp.uu.net usenet/comp.sources.misc '*.Z'
- X.RE
- X.PP
- XAssume there is an entry in the ftpkeys file:
- X.RS
- X.sp
- XCSG ftp.uu.net usenet/comp.sources.games
- X.RE
- X.PP
- XNow to get the sources for the
- X.IR rogue (6)
- Xclone:
- X.RS
- X.sp
- Xsftp -m -k CSG -s volume1/rogue '*.Z'
- X.RE
- X.SH ENVIRONMENT
- X.TP
- X.B FTPKEYS
- XIf set, this variable holds the name of the
- X.I ftpkeys
- Xfile to use.
- XSee the DESCRIPTION section above for more information.
- X.SH FILES
- X.TP
- X.B ftpkeys
- XThe
- X.I ftpkeys
- Xfile is used to store keywords with associated machine\- and
- Xdirectory\-entries.
- XSee the DESCRIPTION section above for more information.
- X.SH "SEE ALSO"
- X.PP
- X.IR archie (1),
- X.IR awk (1),
- X.IR ftp (1),
- X.IR getopts (1),
- X.IR grep (1),
- X.IR sh (1),
- X.IR test (1).
- X.SH BUGS
- X.PP
- XThe keyword lookup scheme could be more fully developed.
- X.SH AUTHOR
- X.PP
- XMichael S Zraly (mzraly@cs.umb.edu)
- END_OF_FILE
- if test 4190 -ne `wc -c <'sftp.1'`; then
- echo shar: \"'sftp.1'\" unpacked with wrong size!
- fi
- # end of 'sftp.1'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-