Linux – How to download a file on a server you’ve already ssh’ed into

linuxscpsshssh-tunnel

I know how to use scp or wget to download a file on a remote server to my local machine. However, if I'm already logged into a server with ssh, is there a command that lets me download a file in the pwd on the server onto my local machine?

I suppose I can use scp, but my local machine is usually behind a router. Would I have to open a port in the router?

Best Answer

What you need to answer is why you don't want to log again ... if you logged once, you can log twice ... especially if you've taken the three minutes it takes to create a key and store the key remotely:

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
2b:4c:11:ab:53:d1:15:90:4f:88:a1:42:da:c5:1c:98 user@localhost
$ ssh-copy-id user@remotehost
Warning: Permanently added 'remotehost' (RSA) to the list of known hosts.
Password:
$ ssh user@remotehost
Last login: Mon Dec 14 21:52:45 2009 from 1.2.3.4
[user@remotehost] $

Back in the times before TCP/IP was commonplace, people used kludges such as X/Modem to handle this. Using this nowadays is kinda silly.