If I'm logged in to a system via SSH, is there a way to copy a file back to my local system without firing up another terminal or screen session and doing scp or something similar or without doing SSH from the remote system back to the local system?
Master connectionIt's easiest if you plan in advance. Open a master connection the first time. For subsequent connections, route slave connections through the existing master connection. In your
If you start an ssh session to the same (user, port, machine) as an existing connection, the second session will be tunneled over the first. Establishing the second connection requires no new authentication and is very fast. So while you have your active connection, you can quickly:
On an existing connection, you can establish a reverse ssh tunnel. On the ssh command line, create a remote forwarding by passing You can automate this further with If you haven't enabled a remote forwarding from the start, you can do it on an existing ssh session. Type Enter There is also some interesting information in this Server Fault thread. |
||||
|
|
|
SSH does support a few commands, via the
The You can re-use the same ssh session if you set up a
you've technically never left the ssh session, and don't need to re-authenticate. Probably more complicated than you'd like, but I can't think of another easy way. |
||||
|
|
|
Those are all very complicated methods.
Then you can copy paste the file with nautilus, gnome, konqueror, dolphin, bash or whatever. |
||||
|
|
|
An even simpler approach: Open Filezilla (or your favorite ftp browser), open an ssh connection to the same site, find the file and drag it across to your local file structure. If you're new to Filezilla, use the "site manager" feature to reconnect fast next time. Yes, I know this is obvious to most of you (and not precisely on point), but some (like me) who found this thread searching for a terminal-only solution may have overlooked the obvious. |
|||
|
|
|
This isn't possible in the "same session", but to make it easier to open another session for copying, you can either use SSH keys or the "Control Master" feature. |
|||
|
|
But none of these are really needed, IMO. The SSH protocol supports multiple channels on a single connection, and the OpenSSH client supports multiplexing. Assuming you have # first connection $ ssh remote # will multiplex over the same connection the original ssh opened $ sftp remote |
|||
|
|
|
There is an explanation of how to get the reverse tunnel automatically set up I have not tried this myself yet, but have kept it in my bookmarks for trying it out at some point in the future. |
||||
|
|
|
Use "!" to convert the file to a ASCII-representation of your file (e.g. uuencode). Then use |
|||
|
|

scp file.foo user@myclient.com:file.foo:P – rahmu Nov 28 '11 at 20:22