Transfer files over an established ssh connection

0

I'm wondering if there's any way, while in an established ssh session, to copy files to and from the source computer, without having to use sftp or scp to create a separate connection, requiring more authentication. I'm looking for either something short and quick to type, or something verbose that I can write a quick-to-type alias or function for.

Here's an example of what an ideal-ish (for me) situation would look like:

$ ssh me@otherhost
password:
$ cpback somefile.txt ~/Documents
copying 'otherhost:~/somefile.txt' to 'localhost:~/Documents/somefile.txt'
$ cpfore otherfile.py ~/Downloads
copying 'localhost:~/otherfile.py' to 'otherhost:~/Downloads/otherfile.py'

In this example, cpback would be to copy from the remote host, and cpfore would copy files from the local host.

Zoey Hewll

Posted 2016-05-12T11:52:48.837

Reputation: 111

i think scp is your best choice, its the simplest by far – TheStarvingGeek – 2016-05-12T12:01:41.750

It's not impossible in theory, but... You establish your ssh session with ssh to set up your terminal, your shell, your environment, to interact and run commands. If you want it to have a transmission feature while in this session, you will have to either code that feature yourself in your own ssh client or use the ~C escape sequence, redirect ports and send data through them and catch it on the other side... that is you must write your own scp inside ssh. I doubt it's worth it. – Gombai Sándor – 2016-05-12T12:30:38.077

Possible duplicate of Execute multiple commands over ssh without reconnecting -- not complete duplicate, but it might help you

– Jakuje – 2016-05-12T15:38:57.273

@Jakuje thanks, that gave at least a workable solution. I can probably use it to make a bunch of alias functions – Zoey Hewll – 2016-05-13T03:25:34.440

Answers

0

Zmodem

It is best to use SCP, there's no problem having scp run at the same time you are using an SSH terminal session. If you use an ssh authentication agent (e.g. Pageant for PuTTY and pscp), you shouldn't need to re-authenticate.

An alternative is a zmodem transfer. You need sz and/or rz on the host computer and an equivalent capability at the client end.

Some ssh clients support zmodem natively (e.g. secureCRT). The ubiquitous PuTTY does not but some forks of PuTTY do: Kitty, ExtraPuTTY and LePuTTY for example.

So if you log in using Kitty as your SSH client you can

  • transmit a file to kitty by invoking the SZ command.
  • transmit a file from kitty by invoking the RZ command and then choosing to send a file using zmodem using the Kitty menu.

You could also probably lash something together using xxd and session logging.

RedGrittyBrick

Posted 2016-05-12T11:52:48.837

Reputation: 70 632