Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Is it possible to transfer files (client-server) from inside a ssh session?.

I know how to transfer files using SCP, This question is about transference from inside a ssh session. For example I start the ssh session:

ssh root@example.com

I perform some operations

echo "Test" > FILE

I transfer the files (pseudocode)

remotecp FILE client_directory

I want to know this because I want to make an automation script from some process (mostly backup operations) and I want to make it the most atomic way possible.

share|improve this question

marked as duplicate by jasonwryan, Anthon, devnull, slm, goldilocks Apr 12 '14 at 15:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

scp is the command to do that. If you set up a ssh key, then you can automate it. – Elliott Frisch Apr 12 '14 at 1:57
I guess it depends if you running your client with a external IP address or not. If so, who mom hates show your IP – RSFalcon7 Apr 12 '14 at 2:45
@ElliottFrisch: I know that method, I want to know if there is a way to do it without closing sessions like the example above. – S182 Apr 12 '14 at 3:16
@Serge Probably with some kermit hack. – Elliott Frisch Apr 12 '14 at 3:28
@jasonwryan: You are right, that question is what I needed. Sorry I did some research but I miss that one. – S182 Apr 12 '14 at 5:52

If you are running your client with a external IP address:

IP=$(who mom hates | awk '{print $5}' | tr -d ')' |tr -d '(')
scp FILE USER@${IP}:~/some/path
share|improve this answer
Thanks, but not external IP address. – S182 Apr 12 '14 at 3:10
Interactively you can suspend the connection with '~&' but I do not think this would work for scripts – RSFalcon7 Apr 12 '14 at 3:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.