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?
It'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.
If the file is small, you can type it out and copy-paste from the terminal output. If the file contains non-printable characters, use an encoding such as base64.
remote.example.net$ base64 <myfile (copy the output)
local.example.net$ base64 -d >myfile (copy the output) Ctrl+D
More conveniently, if you have X forwarding active, copy the file on the remote machine and paste it locally. You can pipe data in and out of
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.
Use "!" to convert the file to a ASCII-representation of your file (e.g.
SSH does support a few commands, via the escape character (
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.
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
What I've found to be the best and most efficient solution is to use
On the server, you use
This bypasses the need to use
One of the many reasons we use SecureCRT — despite preferring open source software where practical — is the ease of doing file transfers. There simply is no direct replacement in the F/OSS world.
SecureCRT started out as a pure Windows program in the mid-1990s but was ported to Mac OS X and Linux a couple of years ago.
SecureCRT has three major features for transferring files to and from a system you are SSH'd into:
Another (IMO) easy way would be:
Or if you prefer something GUI-like, try Midnight Commander. They call the feature Shell-Link. Most distros have em in their package systems as
protected by Community♦ Feb 4 at 16:56
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?