ssh-to-puttyssh-to-puttyIn Windows you can register “url handlers”. These are programs that are run when you try to open a URL (via Start->Run for example). “http://” for example is registered to Internet Explorer by default. “telnet://” also works. This is especially useful in combination with the URL-field of KeePass. Double-clicking on this field tries to “open” the specified URL.

However, “ssh://” is not a standard registered protocol. I’d like Putty to handle this. Also, “telnet://” gets you the standard windows telnet client instead of putty. Putty can be called with command line arguments. Supplying the “telnet://” url as a parameter works, but “ssh://” does not.

Hence, I wrote a very small wrapper program to accept “ssh://” URL’s and convert them to Putty command line arguments:

  • Source code in C: ssh-to-putty.c
  • Compiled Windows executable: ssh-to-putty.exe (some virus-scanners seem to think this is a virus, exe is no longer available, please compile it yourself)
  • Registry commands to set putty as telnet-handler: putty telnet url handler.reg
  • Registry commands to set the wrapper as ssh-handler: putty ssh url handler.reg

Some notes:

  • The registry commands assume Putty and the wrapper are installed in C:\Progs\SSH. If this is not the case, you need to change the .reg-files accordingly
  • The wrapper-program assumes putty.exe to be in the same directory as itself

11 Comments

  1. Bjørn says:

    Just a tip:
    You should “assume” that people just install putty with the default settings.
    Assuming anything else, will render it useless unless people edit the reg-files. 🙂

    Cheers for making the regfiles tho 😛

  2. Niobos says:

    Bjørn,

    I agree. But since putty is normally downloaded as a simple .exe without installer, there is no default installation path. Also, editing a text-file is not very hard.

    Niobos

  3. Felix says:

    Nice work!

    Two notes:
    1) I had to add the directory that contains putty.exe and ssh-to-putty.exe to the PATH variable to make it work. Before that, ssh-to-putty could not find putty, even though both files were located in the same directory.
    2) It would be nice if the ssh-to-putty window would close after starting putty.

    Anyway, thank you very much 🙂

    Best regards
    Felix

  4. John says:

    If you’re having trouble calling PuTTY.exe with a space in the path, this works:

    cmd = “\”C:\\Program Files\\PuTTY\\putty.exe\” -ssh “;

  5. John says:

    Hi,

    me again… I compiled it using tcc ( http://bellard.org/tcc/ )

    It works fine if I do:

    C:\John\tcc>.\ssh-to-putty ssh://login@hostname
    Running: “C:\Program Files\PuTTY\putty.exe” -ssh login@hostname

    But I found that if I call it using a port (e.g. ssh://login@hostname:22)

    then the cmd string gets corrupted.

    It somehow loses the space after the port number, and the @ sign in the user@hostname gets replaced with the 3rd character of the login name.

    C:\John\tcc>.\ssh-to-putty ssh://login@hostname:22
    Running: “C:\Program Files\PuTTY\putty.exe” -ssh -P 22loginghostname

    C:\John\tcc>.\ssh-to-putty ssh://abc@hostname:22
    Running: “C:\Program Files\PuTTY\putty.exe” -ssh -P 22abcchostname

    C:\John\tcc>.\ssh-to-putty ssh://abcd@hostname:22
    Running: “C:\Program Files\PuTTY\putty.exe” -ssh -P 22abcdchostname

    C:\John\tcc>.\ssh-to-putty ssh://abcde@hostname:22
    Running: “C:\Program Files\PuTTY\putty.exe” -ssh -P 22abcdechostname

    I’ve hacked around on it and found that the whole get_putty_cmd function is somehow very touchy.
    If I comment out the whole if(port){…} then it breaks for all URLs, whether they have they port or not.

    If I use an array instead of a pointer for cmd I can get behave more sensibly, but I’ve not got it working quite how I’d like it yet!

  6. Niobos says:

    Hi John,

    I did find a bug in the code which doesn’t look like it’s immediately related, but it might. I also added an additional `fprint` line just above the get_putty_cmd() call. Can you uncomment that and post its output? That log-line will tell you how the ssh-to-putty program understood its command line.

  7. tovog says:

    Hallo,
    can you please help me with launching PuTTY via URL handler?
    I installed putty-telnet-url-handler.reg and reedited registry to destination “C:\Program Files (x86)\PuTTY\PUTTY.EXE”.
    If I click onto ssh://user@IP, error message is PuTTY:”Unable to open connection to IP/, Host does not exist”. Where did the slash ‘/’ came from?
    I also tried to create telnet registry entry – telnet://user@IP >> PuTTY launches OK.
    If I remove ‘user’ – ssh://IP, after several seconds the console appears, but connecting to http://www.esys.sk. Where did the address came from?
    I found also other files.reg in the internet to handle ssh://, almost the same.
    The problem is probably somewhere in settings MS Windows 8.1, but I don’t know where.

    I’d be very happy You helped me.

  8. Niobos says:

    Can you recompile with the fprint() statements uncommented (and probably also the sleep() call, so you have time to see what happens)? That will show in more detail what the wrapper program receives as arguments.

  9. tovog says:

    Thank you for reply,
    but I cannot compile anything, I’m not a SW developer.

  10. Niobos says:

    togov, then how did you get it to work in the first place? I only provide the C-code…

  11. tovog says:

    I’m sorry, I haven’t it read properly. I used only putty-telnet-url-handler.reg without your ‘proxy’ miniapp.