Is there any way to transfer files from a server to a host computer, from within the server ssh connection? I am storage limited on an HPC, and so some jobs require transferring and then deleting files at intermediate stages. It would be great to be able to transfer the files to my host machine from within a job, but I think this might not be possible, given that the unix within an ssh connection does not know that it is an ssh connection.
1 Answer
As B Layer pointed out whenever, you are in a ssh tunnel your command/shell doesn't really know this. Basicly your command/shell works just like it wasn't in a tunnel (the beauty about ssh). That's also why tunnels inside tunnels work!
Goodies gave the answer you were looking for I think. SCP is a very nice tool using ssh to copy files in both a pull and push way depending your situation.
This link gives a very nice overview of the possibilities and the syntax of SCP!
Code you could use: where 192.168.1.100 is your server and 192.168.1.5 your client. Note that dns-names can be used as well.
Pulling: Let's say you have a terminal on your host open, you could do:
scp [email protected]:/tmp/myfile /tmp/files/myfile
This way you are creating a "second tunnel" towards your server.
Pushing: (The other way around) so from your server to your host (essentially it is now a tunnel in your original tunnel):
scp /tmp/myfile [email protected]:/tmp/files/myfile
I hope this explains the concepts a little!
-
Thanks for this suggestion. My host is an virtualbox ubuntu VM running within windows. At the terminal, I see "nb80a@nb80a-VirtualBox:~$". I have tried both nb80a and nb80a@nb80a-VirtualBox in place of "user" in your second suggestion using the address acquired from "${SSH_CLIENT%% *}". I haven't gotten it to work yet. Any ideas?– nb80aJan 12, 2018 at 16:13
-
Your virtualbox shell shows that your user is indeed nb80a on host nb80a-VirtualBox. How is your vm connected to your host? Has your vm his own ip address? Did you use the right one? For and in depth answer you should give a clear overview of your machines, users and ip. Do you have a client on your windows like putty, git bash, bash from wsl?– CiberthJan 12, 2018 at 23:57
$SSH_CLIENT
and$SSH_CONNECTION
for instance. And they both contain the IP address to reach the local/originating host. Tryecho "${SSH_CLIENT%% *}"
to display the IP.