I regularly find myself wanting to copy a file from remote terminal session to my local machine. Usually I log out of the remote session and call an scp transfer from local to copy the file from remote to local. But this feels a little long winded. I would like to transfer the file whilst logged into the remote over SSH to save time. My local machine is connected to the internet from a dynamic IP range so I'm never quite sure how to connect to it remotely. But surely, as the remote session originates from my laptop, there must be a shortcut in scp to get back to my laptop... Right?

link|improve this question
feedback

migrated from stackoverflow.com May 31 '11 at 14:56

This question came from our site for professional and enthusiast programmers.

2 Answers

You can use SSH tunneling for this.

http://en.wikipedia.org/wiki/Tunneling_protocol

Using tunneling you can forward a TCP port either from your local machine to the remote machine, or from the remote machine to your local machine. I use it frequently to forward e.g. SMTP or IMAP ports from a remote machine behind a firewall to my local machine (and then access the services locally, as if they were running locally).

To forward port 22 (SSH) from you local machine to the remote machine try this:

ssh -R12345:localhost:22 yourremoteuser@remotemachine

(Note that localhost refers to the local name of the remote machine)

After running this you should be able to ssh back home using:

ssh -p12345 yourlocaluser@127.0.0.1

When using scp, you would do something like (scp has an uppercase P):

scp -P12345 filename 127.0.0.1:/tmp/filename

Port forwarding in the other direction (from remote to local) using -L instead of -R.

The above commands assume that you are using a terminal ssh client. Graphical clients, like putty for windows also supports tunneling

link|improve this answer
Doesn't answer OP's question whose IP isn't static. – Heandel May 30 '11 at 14:41
Unless I missed something this should fine for the OP to connect from the currently remote machine back to the local. The tunneling will be done through the SSH session. As the SSH connection is setup from the dynamic local machine to the remote it will succeed and will thus be able to setup a listening port on the remote machine that tunnels back to where it came from. – Daniel Lundmark May 31 '11 at 5:50
This will require OP to set up SSH server on his local machine and take care of authentication. So this may be more trouble than it's worth in some use cases. – Septagram Jan 19 at 9:20
feedback

Maybe zssh?

zssh (Zmodem SSH) is a program for interactively transferring files to a remote machine while using the secure shell (ssh). It is intended to be a convenient alternative to scp , allowing to transfer files without having to open another session and re-authenticate oneself.

zssh is an interactive wrapper for ssh

It uses the venerable rz, sz implementations of zmodem file transfer.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.