Monday, December 17, 2007

Tool Of The Day: WinSCP

Tonight I worked on a client's site that required me to use sFTP, instead of the more standard FTP protocol, to interact with it. I was a bit worried, as sitecopy doesn't do sFTP. My client said he used WinSCP to work with the files, so I grabbed it.

Turns out, WinSCP is an impressive little app. It does all the things you'd want an FTP client to do - allowing you to easily drag and drop files and directories. It prompts you when you're overwriting stuff, yet allows you to ignore it. You know, the usual goodies.

What earned it T.O.T.D though, was it's Keep Remote Directory Up To Date. Essentially, you setup WinSCP so that the local directory (left pane of the window) has your source files, and the remote directory (right pane of the window) are showing. You then go to Commands >> Keep Remote Directory Up To Date, answer a bunch of questions, and hit Start. From that point onward, any change you make to your local files are more-or-less instantly copied to the remote system.

It's a really handy feature, and makes remote development a snap.

I should really be looking for this feature in my regular FTP client too. That's not to say that I'm ditching sitecopy anytime soon. Sometimes having explicit control of what gets put to the server is really important. And it's especially useful when you're really developing locally and just want to push the files remotely in a sort of final deployment.

With that said, WinSCP is still quite cool and has opened my eyes to a possibility I hadn't thought of.

Update: Two things I've learned about WinSCP. (1) it does FTP, so I can start using it on a day-to-day basis and not just with sFTP sites. And (2), it's scriptable (Thanks Dave!). Seems like a real find.

5 comments:

  1. It also supports some level of automation! I use it in the batch file that I run after downloading pictures from my camera (copies originals to another drive for backup, resizes each picture into 3 sizes, copies the resized pictures to a directory on my home web server, generates an html page and a jsp page with clickable thumbnails for each directory, and, finally, SCPs the resized pictures and html thumbnail page to another web server).

    As you might imagine, this batch file isn't a just running a bunch of DOS commands. :)

    First of all, it's a 4NT batch file, which means it already has more power available to it than CMD.exe. So, there are loops, conditional execution blocks, subroutines, piping and redirection of stdout/stderr to multiple output locations, environment-variable-string-manipulation, etc.

    It also runs a bash script via cygwin to generate the thumbnail pages. ImageMagick is used to resize the images, and WinSCP is used (see, this comment *IS* relevant! really!) to send the pictures/html page to the off-site web server. The WinSCP part runs a small script, which is generated for each directory, by the batch file.

    I've really been meaning to post this batch file on my blog, but the code is kind of scary. :) I may do it soon, though, since I've already typed up most of the text, in this comment! So much for brevity.

    ReplyDelete
  2. Dave -

    I'd love to see that script. That's cool to know that WinSCP is scriptable.

    I've been slowly embracing this world of Windows rather than always dropping back to my Unix favorites. WinSCP seems like it belongs in my Windows toolbox.

    ReplyDelete
  3. I've been slowly (over the past 4-5 years) reducing my dependence on 4NT, by learning how to do most of the same things in cygwin/bash.

    I use cygwin's ncftp/scp commands for most of my file-transfer needs, but for my photo processing script, I ran into a snag with that. Usually, when I open a new bash shell, I run:
    ssh-agent bash
    ssh-add
    [enter passphrase]

    ...and then I don't need to enter my passphrase again during that bash shell instance, when doing things like ssh/scp (especially useful for cvs-over-ssh).

    But, my picture resizing script starts a new bash instance, and I didn't want to have to enter my passphrase every time I downloaded my pictures (mainly for Lacey's sake, since she downloads the pictures and runs the resizing script some of the time (but also because I'm lazy!)).

    To do this, I needed to have an ssh agent that would persist through an entire windows session. I wasn't able to find a way to get a bash shell running constantly upon windows login, where I could run ssh-agent and ssh-add, enter my passphrase once, and have my batch file (any time it runs) latch onto it. It just wasn't happening. So, I ended up turning to WinSCP, because it can use pageant (Putty's Agent tool) for authentication.

    So, now I have pageant run in my windows startup folder (and in Lacey's as well), so when we log into windows, we just have to enter our passphrase one time in the dialog box that pageant pops up, and then we're able to use WinSCP without entering our passphrase for the rest of our windows session.

    ReplyDelete
  4. I had a similar need for a windows-wide ssh session.

    In my case, I wanted emacs to be able to pick up the ssh agent, so that cvs would work without prompting me for a password.

    I actually found a pretty reasonable solution.

    The ssh agent stuff appears to work by looking for the shell environment varaible SSH_AUTH_SOCK. It needs to be setup to point to the ssh agent directory which is found in /tmp/.

    So I setup my emacs to run the following on startup:

    ls -t /tmp/ssh*/* | grep ssh- | head -1

    That gives me the latest ssh agent directory in /tmp/.

    I then store that filename in the environment variable SSH_AUTH_SOCK and I'm good to go.

    All it means is that I need to run ssh-agent / ssh-add in cygwin before I start emacs, but that's easy enough to do.

    -Ben

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete