#!/bin/sh : # @(#) transfer Transfer files via ftp to/from remote host. # Author: James W. Brown, July 1992. PATH=$PATH:/usr/sbin; export PATH # Add directory containing ping exit_status=0 # No error condition exit code lflag="" # Don't use log by default tdirection=mget # Retrieve file by default tmode=ascii # Use ASCII representation type by default LogFile=$HOME/.transfer_log # Log file path usage_exit(){ cat << EOF >&2 Usage: `basename $0` [-p] [-b] [-l] [-s] [-r rem-dir] -h host file... -p Put instead of take the file -b Use binary instead of ASCII mode -l Store messages from ftp in log file -s Silent mode ( no loging ) -r rem-dir Specify remote directory instead of default (.) -h host Remote host name file... File(s) to be transferred EOF exit_status=1 ; exit } # Set trap to restore .netrc file: trap '[ -f $HOME/.netrc% ] && mv $HOME/.netrc% $HOME/.netrc; exit $exit_status' 0 1 2 3 15 # Process command-line options: if [ "$OPTIND" = 1 ]; then # can use getopts while getopts bh:lpr:s options; do echo $options case "$options" in b) tmode=binary ;; h) host=$OPTARG ;; l) lflag=yes ;; p) tdirection=mput ;; r) remdir=$OPTARG ;; s) LogFile=/dev/null; lflag=yes;; \?) usage_exit ;; esac done shift `expr $OPTIND - 1` # shift options of the way else # getopts not available while [ $# -gt 0 ]; do case $1 in -b) tmode=binary ; shift ;; -h) if [ ! "$2" ]; then echo "-h option requires an argument" >&2 usage_exit else host=$2 ; shift ; shift fi ;; -l) lflag=yes ; shift ;; -s) LogFile=/dev/null; lflag=yes ; shift ;; -p) tdirection=mput ; shift ;; -r) if [ ! "$2" ]; then echo "-r option requires an argument" >&2 usage_exit else remdir=$2 ; shift ; shift fi ;; --) shift; break ;; # end of option list -*) echo "Unrecognized option \"$1\"" >&2 usage_exit ;; *) break ;; # saw first non-option argument esac done fi # Check for non-option (file) argument(s): case $# in 0) echo "Must specify at least one file argument" >&2 usage_exit ;; esac # Check for remote system name, remote directory: if [ ! "$host" ]; then echo "You must specify a remote host machine." >&2 usage_exit elif [ ! "$remdir" ]; then # If no remote directory, then remdir="." # use current directory fi # Echo a packet to see if remote host is reachable: if ping $host 64 1 >/dev/null 2>&1; then # if ping $host >/dev/null 2>&1; then : # No problem else echo "$host either down or doesn't exist." >&2 ; exit_status=2; exit fi # Check .netrc file: if [ -f $HOME/.netrc ]; then hostinfo=`grep $host ${HOME}/.netrc` if [ ! "$hostinfo" ]; then echo "No $host entry found in $HOME/.netrc, exiting..." >&2 exit_status=4 ; exit fi mv $HOME/.netrc $HOME/.netrc% # Save original file # Create new .netrc that's only accessible by owner: touch $HOME/.netrc chmod go-rw $HOME/.netrc else echo "$HOME/.netrc not found, exiting ..." >&2; exit_status=3 ; exit fi # Put the set-up information into .netrc: cat << EOF >> $HOME/.netrc $hostinfo macdef init cd $remdir $tmode prompt $tdirection $* quit EOF # Log transaction in file or on standard output: if [ "$lflag" ]; then date >> $LogFile # note date/time ftp $host >> $LogFile # log ftp messages else ftp $host fi
In reply to Re: using system or Shell
by rbi
in thread using system or Shell
by lanier
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |