How do I download a file from a host i'm already connected to over ssh

8,590

Your machine hostname is not resolvable from the remote host. You should do this the other way round. From your local host:

scp xyz@remote:/home/user/test /home/user

Or the other way is to set up remote port forwarding, so you will be able to connect from your remote machine to your local host. Your command can look like this:

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

Inspired by my answer on SO

Share:
8,590

Related videos on Youtube

Scott Stamile
Author by

Scott Stamile

Updated on September 18, 2022

Comments

  • Scott Stamile
    Scott Stamile over 1 year

    I'm trying to download a file from a linux server i'm already connected to. I know you can use scp to connect to and pull down a file from a host, but that requires still being on local. I could scp the file back to my local machine, but the local machine is not accessible from the host.

    Is there a way to just pull down the file you are already looking at? Something like:

    From the host

    $ download <THEFILE>
    

    This would really just be more convenient than having to go back out to my local terminal than scp the file. Instead you could just say "grab this one" Done.

    I suppose the client would have to know what to do with the file. And i'm pretty sure "terminal.app" does not have a default downloads folder. So perhaps this is not possible.

    BTW I'm connect from a mac to Debian.

    • jc__
      jc__ almost 8 years
      " but the local machine is not accessible from the host." Can you scp from the debian to the mac?
    • Pankaj Goyal
      Pankaj Goyal almost 8 years
      If you're using the new release of iTerm, you can install shell integration, which will allow you to right-click a file and download it to your local host. This is basically a shortcut for opening a new terminal tab or window and simply typing scp [email protected]:/path/to/file ~/Downloads/
    • Scott Stamile
      Scott Stamile almost 8 years
      Just downloaded iTerm and it actually did the job. But it required using an alt terminal app, and i had to install shell integration on the remote server. I might keep using this since iTerm seems pretty powerful. But Jakuje's answer is more inline with what I was looking for.
  • phemmer
    phemmer almost 8 years
    "I could scp the file back to my local machine, but the local machine is not accessible from the host."
  • jc__
    jc__ almost 8 years
    Is that because of a mac limitation like firewall or ssh server nor running, or is it a debian limitation because of... ?? an ip rule...
  • Scott Stamile
    Scott Stamile almost 8 years
    it's because the mac i'm using is on a closed network. so my mac is not accessible from outside our network. In this example the host would be a media temple web server.