View previous topic :: View next topic |
Author |
Message |
pyxel n00b
Joined: 04 Nov 2005 Posts: 44 Location: Bratislava/brussels
|
Posted: Wed Feb 15, 2006 5:08 pm Post subject: resume scp HOWTO |
|
|
Hello, I find a little script for scp resume:
Code: | #!/bin/sh
. /home/pyxel/scripts/functions.sh
usage()
{
echo
echo "Usage: `basename $0` -u(pload) \$localfile \$remotefile"
echo " `basename $0` -d(ownload) \$remotefile \$localfile"
echo
echo " \$remotefile should be in the scp format, i.e.: user@host:filename"
echo " and can be user@host: for uploading"
echo
exit 1
}
[ -z "$1" -o -z "$2" -o -z "$3" ] && usage
option=$1
case $option in
-u*|-U*)
localfile=$2
remote=$3
remove_pattern "${remote}" ":.*$" userhost
remove_pattern "${remote}" "^.*:" remotefile
if [ ! -f "$localfile" ]; then
echo "File not found: $localfile"
usage
fi
if [ x"$userhost" = x"$remote" ]; then usage; fi
if [ x"$remotefile" = x"$remote" -o -z "$remotefile" ]; then remotefile=`basename "$localfile"`; fi
echo "Getting size of remote file:"
localsize=`ls -l "${localfile}" | awk '{ print $5 }'`
remotesize=`ssh "$userhost" "[ -f \"${remotefile}\" ] && ls -l \"${remotefile}\"" | awk '{ print $5 }' `
if [ -z "$remotesize" ]; then remotesize=0; fi
if [ $localsize -eq $remotesize ]; then
echo "Local size equals remote size, nothing to transfer."
exit 0;
fi
echo "Resuming upload of '$localfile' at byte $remotesize..."
dd bs=1 skip=$remotesize "if=${localfile}" | \
ssh "$userhost" "cat >> \"$remotefile\""
echo "done."
;;
-d*|-D*)
localfile=$3
remote=$2
remove_pattern "${remote}" ":.*$" userhost
remove_pattern "${remote}" "^.*:" remotefile
debug_var localfile remote userhost remotefile
if [ x"$localfile" = x"." ]; then localfile=`basename "$remotefile"`; fi
if [ ! -f "$localfile" ]; then
localsize=0;
else
localsize=`ls -l "${localfile}" | awk '{ print $5 }'`
fi
if [ x"$remotefile" = x"$remote" ]; then usage; fi
if [ -z "$localsize" ]; then localsize=0; fi
echo "Resuming download of '$localfile' at byte $localsize..."
ssh "$userhost" "dd bs=1 skip=$localsize \"if=${remotefile}\"" >> $localfile
;;
*)
usage
;;
esac
|
enjoy. |
|
Back to top |
|
|
viperlin Veteran
Joined: 15 Apr 2003 Posts: 1319 Location: UK
|
Posted: Fri Feb 17, 2006 5:41 am Post subject: |
|
|
or use rsync.. |
|
Back to top |
|
|
beandog Bodhisattva
Joined: 04 May 2003 Posts: 2072 Location: /usa/utah
|
Posted: Fri Feb 17, 2006 6:36 am Post subject: |
|
|
I think yafc can do resume too. Can't remember. _________________ If it ain't broke, tweak it. dvds | blurays | blog | wiki |
|
Back to top |
|
|
|