ssh

Is possible to copy files over ssh during an active connection


Very often I need to copy a file from a ssh connection. Lets say a mysql dump. what I do is

local $ ssh my_server
server$ mysqldump database >> ~/export.sql
server$ exit
local $ scp myserver:~/export.sql .

I know ssh has a lot of features like ssh-agent, port-forwarding, etc, and I was wondering if there is anyway to execute scp FROM the server to copy to my local computer (without creating another ssh connection).


Solution

  • I described the solution for similar problem here, but it should help you: https://stackoverflow.com/a/33266538/2196426

    Summed up, yes it is possible using remote port forwarding:

    [local] $ ssh -R 2222:xyz-VirtuaBox:22 remote
    [remote]$ scp -P 2222 /home/user/test xyz@localhost:/home/user