Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

robertcollier4

Instead of having to create a new custom command and passing login information and -cmd on command line (of which unable to pass SSH keyfile and if user doesnt want to use pageant), here is a solution to re-use already existing "Open in PuTTy (Ctrl+J)" command which already passes information through registry. Following method will add "Autocommand" registry value as well to the other registry values that WinSCP already writes in "WinSCP Temporary Session".

1. Download kitty.exe (non-portable) into your WinSCP directory.

2. Create a file named kitty.ini with the following contents in your WinSCP directory. Modify initdelay depending on your connection speed. I found 6 seconds to be a good Autocommand delay to work across a variety of servers.
[KiTTY]
initdelay=6.0

3. Create an Autohotkey script named WinSCPLaunchKittyTempsession.ahk with the following contents that you then compile into WinSCPLaunchKittyTempsession.exe in your WinSCP directory. Pre-compiled script attached.
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\9bis.com\KiTTY\Sessions\WinSCP`%20temporary`%20session, Autocommand, cd "%1%"

Run, kitty.exe -load "WinSCP Temporary Session"


4a. In WinSCP, View>Preferences>Integration>Applications>Putty/Terminal Client Path:
WinSCPLaunchKittyTempsession.exe "!/"

4b. In WinSCP, View>Preferences>Integration>Applications>Putty Registry Key
Software\9bis.com\KiTTY


5. Now you can fast-open in current directory just with WinSCP>"Open in PuTTy" (in the commands menu, or Ctrl+P). No need to create a custom command. And it works with SSH keyfiles and all as well.
martin

robertcollier4 wrote:

Idea: Preferences>Integration>Applications could have an input box for "Autocommand" where we could specify: cd "$REMOTE_PATH$"
If specified, then Autocommand reg value would also get written to [HKEY_CURRENT_USER\Software\9bis.com\KiTTY\Sessions\WinSCP%20temporary%20session]

Please read documentation:
https://winscp.net/eng/docs/integration_putty#kitty
robertcollier4

Petr wrote:

Implemented in 5.2.2 beta and released today :-)

Not really. Just tried 5.2.2 beta. It will open the current session but not switch to the current directory.

What it is currently doing:
With Kitty selected in Preferences>Integration>Applications, and then using Menu Commands>"Open in PuTTy":
1. Writes the current session information to [HKEY_CURRENT_USER\Software\9bis.com\KiTTY\Sessions\WinSCP%20temporary%20session]
2. Launches "<pathtoputty>" -load "WinSCP temporary session"

But it is NOT writing the following which is required for fast-open in current directory:
[m:8911a31c26][HKEY_CURRENT_USER\Software\9bis.com\KiTTY\Sessions\WinSCP%20temporary%20session]
Autocommand="cd \"$REMOTE_PATH$\""[/m:8911a31c26]

Idea: Preferences>Integration>Applications could have an input box for "Autocommand" where we could specify: cd "$REMOTE_PATH$"
If specified, then Autocommand reg value would also get written to [HKEY_CURRENT_USER\Software\9bis.com\KiTTY\Sessions\WinSCP%20temporary%20session]
Petr

Implemented in 5.2.2 beta and released today :-)
martin

robertcollier4 wrote:

In addition to the !p password custom command pattern, it would be helpful if you could also implement a WinSCP custom command pattern to pass the private key file path to a custom command line.

You can use Pageant instead.
robertcollier4

martin wrote:

Btw, the -cmd switch cannot be combined with -load. What limits its usability for exporting sessions from WinSCP to KiTTY.


That is because when -load is used, it reads the cmd from the "Autocommand" data key as defined in the session.

Here is a complete solution that would work:

With kitty_portable.exe (<invalid hyperlink removed by admin>), it stores saved sessions in its "KittyPortable\Sessions" folder as text files.

So, all that needs to be done is to make a copy of "KittyPortable\Sessions\Default%20Settings" as "KittyPortable\Sessions\WinSCPTemporarySession".

Then replace the following lines in text file "KittyPortable\Sessions\WinSCPTemporarySession"
HostName
UserName
Password
PublicKeyFile (if password is blank)
Autocommand

Then launch:
kitty_portable.exe -load "WinSCPTemporarySession"

I can write a simple AutoIt EXE script that would make these text replacements in the session file. However the problem I have is that I cannot pass the "private key file" field from WinSCP via custom command. I do not like to store my passwords but use private key files instead. In addition to the !p password custom command pattern, it would be helpful if you could also implement a WinSCP custom command pattern to pass the private key file path to a custom command line.
martin

robertcollier4 wrote:

I reported this to KiTTY forums and they replied that the fix for this is to increase the initial delay before it starts typing.
https://www.9bis.net/kitty/#!pages/AutomaticCommand.md

Btw, the -cmd switch cannot be combined with -load. What limits its usability for exporting sessions from WinSCP to KiTTY.
martin

Support for this has been implemented, in terms of custom command-like patterns.
robertcollier4

martin wrote:

I've been testing this. It seems pretty unreliable. Obviously, what it does is that it simulates the keystrokes to type the
command. I guess that it often starts typing too early, before the remote session starts reading; and the keystrokes end in vain.

I reported this to KiTTY forums and they replied that the fix for this is to increase the initial delay before it starts typing.
https://www.9bis.net/kitty/#!pages/AutomaticCommand.md
martin

robertcollier4 wrote:

Putty.exe has a similar argument to run a command but it has to be read from a file and cannot be passed directly on the command-line:

This (as opposite to KiTTY simulating keystrokes) makes PuTTY instruct SSH server to start that command instead of the shell. Once that command finishes, the session is terminated. So WinSCP would have to know how to start a shell and append the shell starting command after the cd.
martin

wlad wrote:

what about using KiTTY instead of PuTTY and utilizing KiTTY's ability to execute commands after login ?
c:\kitty\kitty.exe -ssh user@host -pw "password" -cmd "cd $REMOTE_PATH$"

at least supporting this option would be nice

I've been testing this. It seems pretty unreliable. Obviously, what it does is that it simulates the keystrokes to type the command. I guess that it often starts typing too early, before the remote session starts reading; and the keystrokes end in vain.

Also I was not able to make it working together with -load switch that WinSCP is using to pass all parameters to PuTTY.

Anyway, I'll still consider implementing support for this.
wlad

I somehow missed your previous post :oops: , works like a charm, thanks.
wlad

well, yes, but I think the file needs to be at the remote location, which complicates this significantly. Supporting additional argument to the application call is much easier and faster to do. It could be a handy workaround until the definite solution for putty is found. Afaik kitty does all the stuff putty can, so switching to it would be a viable option for users. At least for a large portion of them.
robertcollier4

Putty.exe has a similar argument to run a command but it has to be read from a file and cannot be passed directly on the command-line:
3.8.3.6 -m: read a remote command or script from a file

The -m option performs a similar function to the "Remote command" box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the -m option expects to be given a local file name, and it will read a command from that file.

So perhaps one could make a batch file which would receive the username, hostname, and path from its command line arguments passed to it from a WinSCP Custom Command. Then it would echo cd and path to a temp file. And then run putty.exe with the username, hostname, and the temp file.
robertcollier4

@wlad: based upon your idea passing argument to KiTTY command line, I got it working with a custom command. Here are the steps:

1. In WinSCP - go to View - Preferences - Commands.
2. "Add" command.
3. Select the radio button for "Local command"
4. Description - "Open Current Dir with Kitty"
5. Custom command (replace with your path to KiTTY) -
"D:\PortableApps\KittyPortable\kitty_portable.exe" -ssh !U@!@ -pw "!P" -cmd "cd !/"

6. Push OK to create custom command, OK to leave Preferences dialog.

Now you can invoke the command with File - Custom Commands - Open Current Dir with KiTTY. You can also assign a shortcut key to the custom command.

Note: There seems to be a bug with KiTTY sometimes not correctly detecting that the ssh console is ready and it doesn't run the command passed to it via the command line. The command gets always passed correctly from WinSCP custom command – but sometimes KiTTY does not run it upon login. Works for me about 50% of the time with KiTTY. This is a possible bug with Kitty not always running commands passed to it via command-line.
wlad

what about using KiTTY instead of PuTTY and utilizing KiTTY's ability to execute commands after login ?
c:\kitty\kitty.exe -ssh user@host -pw "password" -cmd "cd $REMOTE_PATH$"

at least supporting this option would be nice
martin

Well that's an obvious solution, with obvious problems. It's not something that can be enabled by default.
someguest

Fast-open of PuTTY in current directory

Hey Admin,

could you add a config-attribute to Options->Preferences->Integration->Applications->PuTTY, so that the Button will open PuTTY in the current directory?

I would love it!

Greetings,
someguest