2

I never heard this possible, so probably the answer is not. But maybe someone knows better.

I know you can use sftp to exchange files between host and remote, and you can both: sftp from host to remote, and from remote to host once you are already connected to the remote with SSH.

But now my question, once you are connected to the remote machine with SSH is this possible to transfer files using already established connection? This is so logical, I am already connected, authentication is done, why not just have something like lls, put. Or use some combination of keys that will bypass remote bash input line and do something between hosts.

3 Answers 3

5

Recent versions of OpenSSH support connection multiplexing. Look at the ControlMaster and ControlPath options for ssh_config.

Using this feature, you'd still have to run scp or sftp to perform a file transfer, but the transfer would run through your existing SSH connection.

2

You will always need to identify yourself to the machines you are connecting to. You can set it up to work with encrypted keys so no password is needed but the authentication is still there.

The easiest way to transfer files between remote systems is scp, part of the ssh package. Lets say your local machine is 1.2.3.4. and your local user tom and the remote machine is 5.6.7.8 and your remote user is jon.

  • To copy a file from the remote server to your local machine when logged in to the server:

    scp /home/jon/foo.txt [email protected]:/home/tom/
    

    Of course, you will still have to identify yourself (to your local machine this time). Not, however, to the server.

  • To copy a file from the remote server to your local machine when not logged in to the server:

    scp [email protected]:/home/jon/foo.txt /home/tom/
    

    This way, you only need to identify yourself once, you don't need to open a separate ssh connection.

You can also copy between remote servers, anywhere you have ssh access to basically. The general format of the command is

scp user1@machine1:/path/to/source user2@machine2/path/to/destination
6
  • The OP specifically wanted to reuse the existing SSH connection, not create a new one. How would he use scp and the existing connection to move files? Apr 26, 2013 at 22:07
  • @DarthAndroid he would not initiate another ssh connection, just use scp, that way only one connection is established. Tongue in cheek, granted, but that's what scp is for. Also, I am assuming (perhaps wrongly, the OP may correct me) from the way the question was worded that the OP is not too familiar with scp which seems to me to be the most logical choice in the situation described.
    – terdon
    Apr 26, 2013 at 22:15
  • 1
    If he's already connected via ssh, why does he need to bother with authentication or hosts in scp ? If it's just reusing the existing ssh connection, isn't he already authenticated and the host doesn't matter? @Kenster found the answer, though I think it needs to be fleshed out a bit more. Apr 26, 2013 at 22:23
  • @DarthAndroid with @Kenster's (very good) suggestion won't the OP still need to identify to the local machine? Why not just run scp instead of connecting over ssh?
    – terdon
    Apr 26, 2013 at 22:28
  • @terdon because I already connected with ssh many hours ago and keep performing various tasks, now I suddenly need only or few files from my local machine... so the question comes
    – exebook
    Apr 27, 2013 at 3:34
0

Using an existing SSH session, but not necessarily SSH itself, you could try the trusty classic Zmodem rz/sz. These utilities may already be available on your system as they are available in RPM and DPKG format in various repos. Otherwise you can download and build them from here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .