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?).

5 thoughts on “GNU Screen and Zmodem”

  1. There’s got to be something I’m not understanding about this – why aren’t you just using scp? Is figuring out the source/remote thing tricky? Or the login a hassle? I have a doskey macro for this whenever I want to upload anything to my webhost (using pscp, naturally).

  2. Why should I have to log in again? If ssh understood zmodem, I could make file transfers without having to make any new connections.

    I usually end up using lftp for file transfers over ssh, it just bugs me that I have to fire up another program.

  3. Why are you logging in again instead of using ssh keys? If you’re worried about the overhead of an additional connection, you can consider using Control sockets in ssh (options ControlMaster and ControlPath in ssh/config).

    This is neat, but just horrid for memory if screen doesn’t queue the zmodem contents to disk prior to dumping it out. It’s also more work than just typing scp [email protected]:file .

  4. I’m using SSH keys, and control sockets, actually. I’m just always looking for more “efficient” ways to do things! :)

    Good point on potential memory usage for zmodem, I hadn’t thought of that.

    The scp example you present is straightforward for sure, but it gets a bit more dodgy if the pathname is long.

Comments are closed.