sftp sucks

Every now and then, I need to modify files hosted on a rented web space where the hoster provides access via SFTP. Since unencrypted connections with plaintext passwords in them suck, of course I'm using SFTP. But this turns out to be a royal pain in the ass, because the Linux SFTP client can only be used interactively and does not provide any means of saving the password because hey, use Public Key Authentication. Sadly, I can't because it's just not available. So every time I want to do a file operation, I need to find the damn credentials in some text file, start an interactive sftp session, do whatever I want to do (interrupted by lots of cd'ing around) and then close the session again to get my bash back.

Obviously, this sucks. I can't establish any kind of workflow because I keep getting interrupted by having to do trivial stuff in a non-trivial way.

I could just use a GUI file manager like Dolphin, but I hate those because they only replace cding around with clicking around, but they don't actually make my life easier. scp would work for me, but unfortunately not for the hoster. Automating the sftp client is not an option because it doesn't work at all without pubkey authentication, and even if I could set that up, automating the sftp client works like this:

(echo progress; echo "put /Django/EFFORT/Creep2Data-2/Test/CH0/new/end.txt"; echo quit)|sftp -b - username@localhost

I mean come on. I'm not doing this. There has to be a better way.

Fortunately, KDE has a tool named kioclient that allows to use the KIO slaves in a nice command-line-ish way. The kio slave for sftp also stores the password, so it doesn't keep asking me all the time. And since the directory structure on the remote side is a clone of the local side, file paths are identical, which makes file operations actually pretty easy to do.

So in order to automate the workflow I'm using, I wrote sftppush.sh which features a couple of hg-like commands to download, view, edit, diff and upload files. So now I can use a workflow that is pretty much the same as if I were using hg, which allows me to actually get stuff done:

localroot$ sftppush ls
files/
something.php
localroot$ sftppush pull something.php
localroot$ vi something.php
# add stuff
localroot$ sftppush diff something.php
--- -   2015-07-26 16:27:22.110686318 +0200
+++ something.php     2015-07-26 16:26:49.000000000 +0200
@@ -91,12 +91,10 @@
  oldstuff
  never mind this
+ stuff I added
  more stuff
  even more stuff
localroot$ sftppush push something.php

This is way more fun.