Skip to content

Instantly share code, notes, and snippets.

@anthager
Last active April 14, 2020 10:40
Show Gist options
  • Select an option

  • Save anthager/8c88ba1ac957dff6802e57f7f2aa1bfe to your computer and use it in GitHub Desktop.

Select an option

Save anthager/8c88ba1ac957dff6802e57f7f2aa1bfe to your computer and use it in GitHub Desktop.
Script for transferring files over ssh when scp is not available. Right now it only works with single files and single level directories and file permissions are ignored. You could prob do some fancy recursive shit for nested directories
#!/usr/bin/env bash
# $1 (first argument) should be the directory you want to transfer
set -e
tmp_file="tmp-file"
folder=""
path=""
[[ -e $tmp_file ]] && rm $tmp_file
[[ -d $1 ]] && path=$1 && folder=$(echo $path | rev | cut -d '/' -f 2 | rev) && echo "mkdir $folder" >>$tmp_file
files=$(ls $1)
for file in $files; do
[[ -n $path ]] && host_path="$path/$file" || host_path="$file"
[[ -n $folder ]] && remote_path="$folder/$file" || remote_path="$file"
file_content=$(cat $host_path)
echo "echo \"$file_content\" > $remote_path" >>$tmp_file
done
ssh -c aes256-cbc -oKexAlgorithms=diffie-hellman-group1-sha1 -p 2222 dvader@localhost "/bin/bash -s" <$tmp_file
rm $tmp_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment