Tip of the Day: socat and sftp

For a protocol which has unarguably changed life as we know it for the better, the SSH tool suite sure does suck. I guess ssh is ok, but scp blindly follows symlinks, inevitably leading to shitshows of immense proportions when it encounters a recursive symlink. (Developers, in a bizarre show of hubris and misplaced idealism, refuse to do anything about it, despite one user complaint after the next). And sftp, presumably for reasons of nostalgia, has no readline support. Shit, the version I use don’t even seem to handle backspace correctly.

One of these problems we can fix, thanks to socat. It’s kind of hard to describe what socat is, in the same way it’s hard to describe what ‘matter’ is. It’s kind of like everything in /usr/bin has been simmered and reduced down to their pure essences, then distilled into a glistening crystal orb. That orb is socat, and you can accomplish a tremendous array of bizarre yet fundamentally useful tasks with it. Sometimes for fun I like to read the list of example socat uses as my little homunculus imagines doing each one in turn.

Anyways, one of the things socat can do is wrap readline around arbitrary interactive programs. Don’t ask me how. Here’s the incantation:
 socat READLINE,noecho='[Pp]assword:' EXEC:'sftp user@host',pty,setsid,ctty 

Now you can use your arrow keys and whatnot to edit the commandline and scroll through the command history in sftp like a normal human being and not an immortal god-creature who need not worry about spending the precious moments of his mortality backspacing and re-typing. Welcome to the early 1990’s, my friend.