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
@AhsenBaig
Copy link
Author

AhsenBaig commented Jul 7, 2020

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.

  1. Save bat file to a known path will need this below.

  2. Launch WinSCP

  3. Preferences (CTRL+ALT+P)-> Integration -> Applications, for PuTTY/Terminal client path:
    <drive_letter>:\<Path_to_file>\WinSCP_WindowsTerminal.bat !U@!@ !# !/ "!N"

  4. Ok.

  5. Open Session in PuTTY (CTRL+P) launches Windows Terminal

@IrealiTY
Copy link

This works great! Thanks for this.
Do you think there'd be a way to keep the session password saved too?

@AhsenBaig
Copy link
Author

AhsenBaig commented Jul 12, 2020

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.

@AhsenBaig
Copy link
Author

WinSCP released new docs that show other methods including WSL: https://winscp.net/eng/docs/integration_putty#wsl

@avmaksimov
Copy link

Unfortenutely, it doesn't work for me. I see this error.
image

And BTW I want to pass password entering. Is it possible as I did with Putty?

@nikhilj1
Copy link

nikhilj1 commented May 13, 2024

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.

@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