Topic "fast-open of putty in current directory"

Author Message
someguest

Guest


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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Please read topics linked from below tracker entry for reasons it is not easy to do:
http://winscp.net/tracker/show_bug.cgi?id=326
Maybe you can suggest some solution?
_________________
Martin Prikryl
someguest

Guest


Hi!

Something like CreateProcess() with the Command "putty -ssh telnet://$ip -l $username -pw $pass".

And then send the Keystrokes for "cd $dir" to the Thread-ID with the PostThreadMessage function: http://msdn.microsoft.com/en-us/library/ms644946%28VS.85%29.aspx

Like questioned here: http://www.daniweb.com/software-development/cpp/threads/185513

Could work? Very Happy
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Well that's obvious solution, without obvious problems. It's not something that can be enabled by default.
_________________
Martin Prikryl
wlad

Guest


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
robertcollier4
[View user's profile]

Joined: 2013-04-04
Posts: 8
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) -
Code:
"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.
robertcollier4
[View user's profile]

Joined: 2013-04-04
Posts: 8
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:
Quote:
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.
wlad

Guest


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.
wlad

Guest


I somehow missed your previous post Embarassed , works like a charm, thanks.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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:
Quote:
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.

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.
robertcollier4
[View user's profile]

Joined: 2013-04-04
Posts: 8
prikryl 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.
http://www.9bis.net/kitty/?page=Automatic%20command&zone=en
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Support for this has been implemented, in terms of custom command-like patterns.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
http://www.9bis.net/kitty/?page=Automatic%20command&zone=en

Btw, the -cmd switch cannot be combined with -load. What limits its usability for exporting sessions from WinSCP to KiTTY.
robertcollier4
[View user's profile]

Joined: 2013-04-04
Posts: 8
prikryl 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 [url=<invalid hyperlink removed by admin>]kitty_portable.exe[/url], 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
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
_________________
Martin Prikryl
Petr
[View user's profile]
Moderator
Joined: 2006-01-26
Posts: 50
Implemented in 5.2.2 beta and released today Smile
robertcollier4
[View user's profile]

Joined: 2013-04-04
Posts: 8
Petr wrote:
Implemented in 5.2.2 beta and released today Smile

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:
[HKEY_CURRENT_USER\Software\9bis.com\KiTTY\Sessions\WinSCP%20temporary%20session]
Autocommand="cd \"$REMOTE_PATH$\""


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]
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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:
http://winscp.net/eng/docs/integration_app#kitty
_________________
Martin Prikryl
robertcollier4
[View user's profile]

Joined: 2013-04-04
Posts: 8
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.
Code:
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:
Code:
WinSCPLaunchKittyTempsession.exe "!/"

4b. In WinSCP, View>Preferences>Integration>Applications>Putty Registry Key
Code:
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.
WinSCPLaunchKittyTempsession.zip (242.68 KB) [Download]

Description: WinSCPLaunchKittyTempsession.zip

Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License