Autor: Wojciech Myszka (myszka_at_ldhpux.immt.pwr.wroc.pl)
Data: Thu 28 Sep 1995 - 08:39:04 MET
On 27 Sep 1995, Krzysztof Gozdziewski pisal:
> napisac cos w rodzaju skryptu dla ncftp. Moze ktos zechcialby podeslac
> lepszy (inny) lub prostszy sposob ?
---
Mozna skorzystac z mozliwosci jakie daj plik .netrc. Jest to opisane
w rozdziale poswieconym ftp w:
http://www.immt.pwr.wroc.pl/export_hp/tool/tool.html
Ponizej skrypcik automatycznie korzystajacy z tej mozliwosci
Pozdrowienia
Wojtek
--------------------------------------------------------------------------
:
# @(#) transfer Transfer files via ftp to/from remote host.
# Author: James W. Brown, July 1992.
# Revised: Becca Thomas, July 1992.
$DBG_SH # Place your favorite shell debugging directive here
PATH=$PATH:/usr/etc; 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] [-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
-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: options; do
case "$options" in
b) tmode=binary ;;
h) host=$OPTARG ;;
l) lflag=yes ;;
p) tdirection=mput ;;
r) remdir=$OPTARG ;;
\?) 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 ;;
-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 /etc/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
To archiwum zostało wygenerowane przez hypermail 2.1.7 : Wed 19 May 2004 - 15:52:48 MET DST