0

This question already has an answer here:

I want to copy a file via ssh when I've logged in. What scp does is that it copies the files by login, password, path. What I want is to be able to do the same thing when I'm "inside", ideally without providing the login and password:

$ ssh root@123.123.243.63
root's password:

Welcome to .....
Last login: ....
root@folder1:~# // How do I download (or upload) the files when I'm here?

marked as duplicate by Gilles ssh Dec 9 '14 at 22:55

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.

1

As pointed out in this Ask Ubuntu answer, you may use zssh instead of ssh. When using zssh, you'll be able to switch to file transfer mode using Ctrl + @. This should allow you to transfer files back and forth between the local and remote ends of your active connection.

Another trick pointed out in that answer is to send ssh to the background while you call scp. This may require re-authentication though, but if you setup passkey authentication, this shouldn't be a problem. To send ssh to the background, hit Ctrl + Z. You should then be able to call scp, and get ssh back when you're done, using fg.

Edit: as pointed out by muru, in order to handle Ctrl + Z locally, and not remotely, you'll have to use Enter, ~, Ctrl + Z. See about SSH escape sequences.

Basically, scp and ssh just don't work the same way. You'll need a trick to make one do the other's job. Some of those tricks are given in the question I linked earlier.

  • Is sending ssh to the background shell dependent? I couldn't do it on zsh with Ctrl-Z. – muru Dec 9 '14 at 8:33
  • @muru This is handled by the terminal, but requires a little bit more setup (see the Ask Ubuntu answer) ; otherwise, the Ctrl+Z sequence is handled remotely. I'll edit my answer. – John WH Smith Dec 9 '14 at 8:35
  • Ah, so this is through Enter-~. – muru Dec 9 '14 at 8:36
0

If you set up a control file, you can reuse the existing connection authentication. From man ssh_config:

 ControlMaster
         Enables the sharing of multiple sessions over a single network
         connection.  When set to “yes”, ssh(1) will listen for
         connections on a control socket specified using the ControlPath
         argument.  Additional sessions can connect to this socket using
         the same ControlPath with ControlMaster set to “no” (the
         default). ...
         Two additional options allow for opportunistic multiplexing: try
         to use a master connection but fall back to creating a new one if
         one does not already exist.  These options are: “auto” and
         “autoask”.  The latter requires confirmation like the “ask”
         option.

So, if you connect using the options -o ControlMaster=auto -o ControlPath=/tmp/ssh-%h-%r, the first connection can be reused for scp. This can be set in your ~/.ssh/config:

Host some-host
  ControlMaster auto
  ControlPath=/tmp/ssh-%h-%r

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