Here are the scripts I use for that job. I don't know if they work with Open-SSH but they do work with SSH.com's SSH. First, putting files onto another server:
Code:
#!/bin/sh
#
# SFTPput [user@]host directory file ... - (secure) FTP files in dir from host
#
# Sat Mar 11 11:18:20 GMT 2006
#
# usage - display usage message
#
usage () {
echo "Usage: $NAME [user@]host dir file ..." >&2
exit 1
}
# mkTmp - make temp dir and delete it automatically on exit
# Eg: ... > $TMP/temp
#
mkTmp() {
TMP=/tmp/$NAME.$$
trap 'rm -r $TMP > /dev/null 2>&1' 0 1 2 3 4 5 6 7 8 9 10 12 13 14 15
mkdir $TMP
}
# checkCurrent - check IP adress for home is today's
#
checkCurrent () {
set `date`
today=$2$3
set -- `ls -l $HOME/var/home`
stored=$6$7
timeORyear=$8
case $timeORyear in
??:??)
test $today = $stored || old
;;
*)
old
;;
esac
}
# old - say it's old
#
old () {
printf "$NAME: home's IP older than today\n" >&2
exit 3
}
NAME=`basename $0`
if [ $# -lt 3 ]
then usage
else host=$1
dir=$2
shift 2
fi
case $host in
*@home)
checkCurrent
sedCmd="s/home/`cat $HOME/var/home`/"
host=`echo $host | sed "$sedCmd"`
;;
home)
checkCurrent
host=`cat $HOME/var/home`
;;
*@office)
host=`echo $host |
sed 's/office/cms-2313-02.cms.shu.ac.uk/'`
;;
office)
host=cms-2313-02.cms.shu.ac.uk
;;
esac
case $host in
*@*)
;;
*)
host=cmsps@$host
;;
esac
mkTmp
{
printf "binary\ncd $dir\n"
for file
do if [ -f $file ]
then echo put $file
else echo "$NAME: $file: doesn't exist (skipped)" >&2
fi
done
echo quit
} > $TMP/commands
sftp -B $TMP/commands $host > $TMP/errors
return=$?
case $return in
0)
exit
;;
2)
echo $NAME: $dir: no such directory >&2
exit $return
;;
*)
echo $NAME: ERROR $return >&2
cat $TMP/errors >&2
exit $return
esac
Here is its partner:
Code:
#!/bin/sh
#
# SFTPget [user@]host directory file ... - (secure) FTP files in dir from host
#
# Sat Mar 11 11:28:20 GMT 2006
#
# usage - display usage message
#
usage () {
echo "Usage: $NAME [user@]host dir file ..." >&2
exit 1
}
# mkTmp - make temp dir and delete it automatically on exit
# Eg: ... > $TMP/temp
#
mkTmp() {
TMP=/tmp/$NAME.$$
trap 'rm -r $TMP > /dev/null 2>&1' 0 1 2 3 4 5 6 7 8 9 10 12 13 14 15
mkdir $TMP
}
# checkCurrent - check IP adress for home is today's
#
checkCurrent () {
set `date`
today=$2$3
set -- `ls -l $HOME/var/home`
stored=$6$7
timeORyear=$8
case $timeORyear in
??:??)
test $today = $stored || old
;;
*)
old
;;
esac
}
# old - say it's old
#
old () {
printf "$NAME: home's IP older than today\n" >&2
exit 4
}
NAME=`basename $0`
if [ $# -lt 3 ]
then usage
else host=$1
dir=$2
shift 2
fi
case $host in
*@home)
checkCurrent
sedCmd="s/home/`cat $HOME/var/home`/"
host=`echo $host | sed "$sedCmd"`
;;
home) checkCurrent
host=`cat $HOME/var/home`
;;
*@office)
host=`echo $host |
sed 's/office/cms-2313-02.cms.shu.ac.uk/'`
;;
office)
host=cms-2313-02.cms.shu.ac.uk
;;
esac
case $host in
*@*)
;;
*)
host=cmsps@$host
;;
esac
mkTmp
{
printf "binary\ncd $dir\n"
for file
do echo get $file
done
echo quit
} > $TMP/commands
sftp -B $TMP/commands $host > $TMP/errors
return=$?
case $return in
0)
exit
;;
2)
echo $NAME: $dir: no such directory >&2
exit $return
;;
6)
printf "$NAME: no such file(s): " >&2
grep '(src): no such file' $TMP/errors |
sed 's?.*/??
s/.).*//' |
fmt >&2
exit $return
;;
*)
echo $NAME: ERROR $return >&2
cat $TMP/errors >&2
exit $return
esac