How to copy a file without using scp inside an ssh session?

To send a file:

cat file | ssh ajw@dogmatix "cat > remote"

Or:

ssh ajw@dogmatix "cat > remote" < file

To receive a file:

ssh ajw@dogmatix "cat remote" > copy

Try this:

cat myfile.txt | ssh me@otherhost 'cat - > myfile.txt' 

You can use xxd and some ugly quoting to copy over multiple files as well as run commands on them and execute them:

ssh -t [email protected] "
echo $'"$(cat somefile | xxd -ps)"' | xxd -ps -r > "'somefile'"
chmod +x somefile
echo $'"$(cat someotherfile | xxd -ps)"' | xxd -ps -r > "'someotherfile'"
chmod +x someotherfile
./somefile
./someotherfile
"

Tags:

Linux

Unix

Ssh

Scp