GNU Screen and Zmodem

One thing I’ve wanted to do for a while is initiate a file transfer during an ssh session without having to do anything special, ie: let the terminal, the tunnel, or something I’m already using handle the transfer after I’ve told it to start, say, from the command line.

Here’s my goal:

  1. ssh to remote host
  2. initiate file transfer from the command line
  3. file is transferred between local and remote hosts

I’m not quite there yet, but I’ve found something interesting using GNU Screen that is just teasing me to spend more time on the problem. Also, since I use Screen constantly, this is a somewhat acceptable workaround for now. Here’s what I can do, thanks to Michael Schroeder’s help (he wrote the book on Screen).

Send a file from the remote host to the local host:

  1. start a Screen session on the local host
  2. configure Screen to “catch” zmodem traffic (CTRL-A:zmodem catch<ENTER>)
  3. execute sz FILE from the command line
  4. hit <ENTER> when Screen brings up the default receive command
  5. bam, the file is available on the local host!

Send a file from the local host to the remote host:

  1. start a Screen session on the local host
  2. configure Screen to “catch” zmodem traffic (CTRL-A:zmodem catch<ENTER>)
  3. execute rz from the command line (no need to specify filename)
  4. add local filename when Screen brings up the default send command, then hit <ENTER>
  5. bam, the file is available on the remote host!

Here’s another cool thing to try. Transferring files using Screen sessions on both the local and remote hosts:

  1. start a Screen session on the remote host
  2. configure remote host Screen to “pass” zmodem traffic (CTRL-A:zmodem pass<ENTER>)
  3. detach remote host Screen session
  4. start a Screen session on the local host
  5. configure local host Screen to “catch” zmodem traffic (CTRL-A:zmodem catch<ENTER>)
  6. ssh to remote host within Screen
  7. attach to the Screen session on the remote host (yep, now you’re “2 deep”)
  8. continue as in previous two walkthroughs. Remote host Screen passes zmodem traffic to local host Screen!

A word of caution, as of GNU Screen version 4.0.3, this is an experimental feature. I just had Screen crash on me after (successfully) transferring a 10MiB file.

I’m getting a little closer to my goal, but I think I need to learn a little more about zmodem and ssh first. I tried to get zssh fired up, but it complains about no ptys being available (possibly needs to be updated to use udev?).