Skip to content

Instantly share code, notes, and snippets.

@AhsenBaig
Last active February 10, 2025 22:19
Show Gist options
  • Save AhsenBaig/0bceed5bff813c1bc3edb2f883734b2c to your computer and use it in GitHub Desktop.
Save AhsenBaig/0bceed5bff813c1bc3edb2f883734b2c to your computer and use it in GitHub Desktop.
WinSCP - Replace PuTTY with Windows Terminal
@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
@syarfandi
Copy link

Use this instead :
wt.exe cmd /k ssh !U@!@
and disable
Remember session password and pass it to PuTTY' (SSH)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment