Skip to content

Instantly share code, notes, and snippets.

@BrianTheCoder
Created March 1, 2014 05:22
Show Gist options
  • Save BrianTheCoder/9285637 to your computer and use it in GitHub Desktop.
Save BrianTheCoder/9285637 to your computer and use it in GitHub Desktop.
#!/bin/bash
FILE=$1
HOSTNAME=$2
USER=cfeduke
SPLIT_SIZE=3145728 # bytes, 3 MiB (1024*1024*3)
SCP_MAX_COUNT=4 # no. of maximum scps at once
cp $FILE /tmp
cd /tmp
FILE=$(basename $FILE)
split -b$SPLIT_SIZE $FILE file-part-
scp_count=0
for part in file-part-*; do
scp -B "$part" $HOSTNAME:~ &
scp_count=$(($scp_count+1))
if [ "$scp_count" -gt $SCP_MAX_COUNT ]; then
wait
$scp_count=0
fi
done
if [ "$scp_count" -gt 0 ]; then
wait
fi
ssh -o "BatchMode yes" -t $HOSTNAME "cat /home/$USER/file-part-* >> /home/$USER/$FILE && rm /home/$USER/file-part-*"
rm file-part-*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment