HTML code to open PuTTY client from browser

ε祈祈猫儿з 提交于 2019-11-30 14:48:56

I've done it following the info of this blog post.

For future reference in case the original page becomes missing, here is the process:

  1. you cannot directly map the ssh:// scheme to PuTTY, but you can map it to an intermediary script which will in turn lanch PuTTY with the right arguments. Mine is called putty_ssh.bat and has the following content:

    @echo off
    set var=%1
    set extract=%var:~6,-1%
    "C:\Program Files (x86)\PuTTY\putty.exe" %extract%
    
  2. the script has to be registered in the registry. You can just create a ssh.reg file with the following content and open it (customizing last line as needed):

    REGEDIT4
    [HKEY_CLASSES_ROOT\ssh]
    @="URL:ssh Protocol"
    "URL Protocol"=""
    [HKEY_CLASSES_ROOT\ssh\shell]
    [HKEY_CLASSES_ROOT\ssh\shell\open]
    [HKEY_CLASSES_ROOT\ssh\shell\open\command]
    @="\"C:\\path\\to\\putty_ssh.bat\" %1"
    

When I click on ssh:// links in web pages, it now opens PuTTY.

PuTTY unfortunately does not associate itself with the ssh:// or any other URLs.

You can associate an application with a protocol manually. But it's not trivial. For instructions, see below.

Easier way is to install WinSCP SFTP client. WinSCP 5.9 and newer registers itself to handle the ssh:// URL and opens the session specified by the URL in PuTTY.

So basically, if you just install WinSCP, it will make PuTTY handle the ssh:// URLs, without the below manual tweaks.

(I'm the author of WinSCP)


To register an application manually, see the MSDN article Registering an Application to a URI Scheme.

Basically you add a registry key like:

[HKEY_CLASSES_ROOT\ssh]
@="URL: SSH Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\ssh\DefaultIcon]
@="\"C:\\Program Files (x86)\\PuTTY\\PuTTY.exe\",0"

[HKEY_CLASSES_ROOT\ssh\shell]

[HKEY_CLASSES_ROOT\ssh\shell\open]

[HKEY_CLASSES_ROOT\ssh\shell\open\command]
@="\"C:\\Program Files (x86)\\PuTTY\\PuTTY.exe\""

Though the above passes a whole URL to the PuTTY command-line. And PuTTY does not understand the ssh:// prefix. So you would have to add a wrapper script that strips the ssh:// and passes only a user and a host to PuTTY.

For that see:
https://johnsofteng.wordpress.com/2009/05/12/launch-putty-from-browser/


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!