-
-
Save AhsenBaig/0bceed5bff813c1bc3edb2f883734b2c to your computer and use it in GitHub Desktop.
@echo off | |
@REM WinSCP PuTTY/Terminal client path: | |
@REM "<drive>:\<Path_to_file>\WindowsTerminal.bat" "!K" !U@!@ !# !/ "!N" | |
@REM setlocal | |
setlocal enabledelayedexpansion | |
SET "debugMode=n" | |
SET "Line=======================" | |
@set /a count = 1 | |
@REM SET pem extension from ppk file | |
SET "KeyExt=pem" | |
SET "KeyFile=%~1" | |
@REM SET KeyFile value | |
SET "KeyFile=!KeyFile:ppk=%KeyExt%!" | |
SET "SSH_PATH=cd %4 && exec bash -l" | |
@REM SSH Command for Terminal: | |
SET "SSH_CMD=ssh -i "%KeyFile%" -p %3 -t %2 \"!SSH_PATH!"\" | |
IF /I %debugMode% == y ( | |
ECHO !Line! | |
ECHO Debuging | |
ECHO !Line! | |
ECHO | |
ECHO !Line! | |
ECHO All prameters: %* | |
for %%x in (%*) do ( | |
echo Cnt: !count! Val: %%x | |
SET /a count+=1 | |
) | |
ECHO !Line! | |
ECHO GET KeyFile value: %1 | |
ECHO SET KeyFile value: "!KeyFile!" | |
ECHO !Line! | |
ECHO Example: | |
SET "EXAMPLE_PATH=cd <remote_path>/<sub_dir>/ && exec bash -l" | |
ECHO "ssh -i <key> -p <port> -t \"!EXAMPLE_PATH!"\"; | |
ECHO | |
ECHO !Line! | |
ECHO Parsed: | |
ECHO SSH_PATH: !SSH_PATH! | |
ECHO SSH_CMD: !SSH_CMD! | |
ECHO !Line! | |
PAUSE | |
) ELSE ( | |
ECHO Debug: off | |
) | |
@REM For Current Windows Terminal | |
@REM ECHO C:\Windows\System32\cmd.exe /c start /b %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\wt.exe !SSH_CMD! | clip && notepad | |
C:\Windows\System32\cmd.exe /c start /b %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\wt.exe !SSH_CMD! | |
ENDLOCAL |
This works great! Thanks for this.
Do you think there'd be a way to keep the session password saved too?
This works great! Thanks for this.
Do you think there'd be a way to keep the session password saved too?
I haven't tried it but see if the WinSCP settings: "Remember session password and pass to PuTTY (SSH)" works. Else, you have to use the !P parameter. Yet this is not recommended as it's being passed in cleartext. Set up an SSH key instead: https://serverfault.com/a/241593
Also, see WinSCP documentation for https://winscp.net/eng/docs/ui_pref_integration_app.
WinSCP released new docs that show other methods including WSL: https://winscp.net/eng/docs/integration_putty#wsl
I use:
wt.exe -w 0 ssh.exe -i !K.pem !U@!@ -p !# -t "cd !/ \; /bin/bash -l"
Openssh Key file is saved as [file].ppk.pem & [file].ppk is the PuttyKeyfile I use for Winscp.
This omits the use of above script.
Use this instead :
wt.exe cmd /k ssh !U@!@
and disable
Remember session password and pass it to PuTTY' (SSH)
This gits is for getting WinSCP to work with Windows Terminal. WinSCP currently doesn't currently launch PowerShell ps1 (opens it in notepad) so a bat file had to be used.
Save bat file to a known path will need this below.
Launch WinSCP
Preferences (CTRL+ALT+P)-> Integration -> Applications, for PuTTY/Terminal client path:
<drive_letter>:\<Path_to_file>\WinSCP_WindowsTerminal.bat !U@!@ !# !/ "!N"
Ok.
Open Session in PuTTY (CTRL+P) launches Windows Terminal