1

Considering I have connected via ssh to a remote host and I want to copy a file from that remote host to my local device:

I know that I can just copy that file from a shell on the local device by using something like:

> scp user@remote:/path/to/file ./

and be done with it.

But when I am already on the remote host and I have no idea what my local IP is, is there a way to specify a copy to the local machine to the directory I was when I connected via ssh?

> pwd
/home/user/documents/stuff
> ssh user@remote
Connected to remote host
> scp file.txt REMOTECONNECTION
[==========] 100% Done.
> exit
> ls
file.txt
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
salbeira
  • 149

1 Answers1

2

Yes, this is in fact possible using the environment variable SSH_CLIENT.

Try this:

scp /path/to/my_file username@$(echo $SSH_CLIENT | awk '{ print $1}'):

Note that this will push the file to your home directory.

Panki
  • 6,664