scp Backward
January 10, 2011
I get into this situation all the time:
- ssh into a remote box
- Look around for a file
- Want to copy the file back to my local box
Maybe I'm missing some magic everyone else knows, but at this point I usually:
- Grumble
- Run pwd on the remote box
- Copy the path to the clipboard
- Open another console
- scp the pasted path to my local box
or:
- Grumble
- Make sure I'm running sshd locally
- Figure out the IP address of my local box
- scp the file to my local box
Both suck. Here's my latest solution. As long as I have sshd running on the local machine and this script on the remote machine:
#!/bin/bash
RIP=${SSH_CLIENT%% *}
scp $@ $RIP:
... I can do the following:
$ ssh foobar.com
$ cd some/place
$ ls # looking ...
$ cd some/other/place
$ ls # looking ... etc.
$ rscp -r some_file_or_dir
... to copy some_file_or_dir
into my home dir on my local box.