Last active
April 14, 2020 10:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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