User Tools

Site Tools


linuxtips:sshpartialdownload

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

linuxtips:sshpartialdownload [2012/01/14 03:51]
0.0.0.0 created
linuxtips:sshpartialdownload [2012/01/14 05:07] (current)
mschiff Page moved from sshpartialdownload to linuxtips:sshpartialdownload
Line 17: Line 17:
  
 <code> <code>
-  - !/bin/bash +#!/bin/bash 
-  -  scp+.sh +scp+.sh 
-  -  get/put files via ssh and +get/put files via ssh and 
-  -  continue partial downloads/uploads or host-to-host transfers +continue partial downloads/uploads or host-to-host transfers 
-  -  +# 
-  -  Copyright (c) 2005-2008 by Marc Schiffbauer +Copyright (c) 2005-2008 by Marc Schiffbauer 
-  -  +Version 2.0 
-  -  Version 2.0 +#
-  - +
  
 SSH_OPTS="-o ServerAliveInterval=5 -o ServerAliveCountMax=3" SSH_OPTS="-o ServerAliveInterval=5 -o ServerAliveCountMax=3"
 BLOCK_SIZE="1500" # Bytes BLOCK_SIZE="1500" # Bytes
  
-  -  URL like "user@host:path/to/file"+URL like "user@host:path/to/file"
 SRC_URL="$1" SRC_URL="$1"
 SRC_URL_HOST="${SRC_URL%%:*}" SRC_URL_HOST="${SRC_URL%%:*}"
Line 40: Line 39:
  
 if [[ -z "$SRC_URL" || -z "$DST_URL" ]]; then if [[ -z "$SRC_URL" || -z "$DST_URL" ]]; then
-<code> 
   echo ""   echo ""
   echo "  Syntax: $(basename $0) <src> [[<dst>]]"   echo "  Syntax: $(basename $0) <src> [[<dst>]]"
   echo ""   echo ""
   echo "    src/dst: [[[user@]]host:]/path/to/file"   echo "    src/dst: [[[user@]]host:]/path/to/file"
-  exit 1</code>+  exit 1
 fi fi
  
 if [[ $SRC_URL_HOST == $SRC_URL_FILE ]]; then if [[ $SRC_URL_HOST == $SRC_URL_FILE ]]; then
-<code> +  SRC_CMD="sh -c"
-  SRC_CMD="sh -c";</code>;+
 else else
-<code> +  SRC_CMD="ssh $SSH_OPTS $SRC_URL_HOST"
-  SRC_CMD="ssh $SSH_OPTS $SRC_URL_HOST";</code>;+
 fi fi
 if [[ $DST_URL_HOST == $DST_URL_FILE ]]; then if [[ $DST_URL_HOST == $DST_URL_FILE ]]; then
-<code> +  DST_CMD="sh -c"
-  DST_CMD="sh -c";</code>;+
 else else
-<code> +  DST_CMD="ssh $SSH_OPTS $DST_URL_HOST"
-  DST_CMD="ssh $SSH_OPTS $DST_URL_HOST";</code>;+
 fi fi
  
-DST_SIZE=$($DST_CMD "if [[|-f '$DST_URL_FILE' ]]; then find '$DST_URL_FILE' -printf '%s'; else echo 0; fi")+DST_SIZE=$($DST_CMD "if [[sshpartialdownload|-f '$DST_URL_FILE' ]]; then find '$DST_URL_FILE' -printf '%s'; else echo 0; fi")
 PADDING=$((BLOCK_SIZE-DST_SIZE%BLOCK_SIZE)) PADDING=$((BLOCK_SIZE-DST_SIZE%BLOCK_SIZE))
  
-$SRC_CMD "if [[|$PADDING -ne $BLOCK_SIZE ]]; then dd if='$SRC_URL_FILE' ibs=1 skip=$DST_SIZE status=noxfer count=$PADDING 2>/dev/null; PADDING=$PADDING; \ +$SRC_CMD "if [[sshpartialdownload|$PADDING -ne $BLOCK_SIZE ]]; then dd if='$SRC_URL_FILE' ibs=1 skip=$DST_SIZE status=noxfer count=$PADDING 2>/dev/null; PADDING=$PADDING; \ 
-<code> +  else PADDING=0; fi; dd if='$SRC_URL_FILE' bs=$BLOCK_SIZE skip=\$((($DST_SIZE+PADDING)/$BLOCK_SIZE))" | $DST_CMD "cat >> $DST_URL_FILE"
-  else PADDING=0; fi; dd if='$SRC_URL_FILE' bs=$BLOCK_SIZE skip=\$((($DST_SIZE+PADDING)/$BLOCK_SIZE))" | $DST_CMD "cat >> $DST_URL_FILE";</code>;+
 exit $? exit $?
 </code> </code>
linuxtips/sshpartialdownload.1326509495.txt.gz · Last modified: 2012/01/14 03:51 by 0.0.0.0