Issue with external editor (.bat) for decrypting .gpg files – script receives wrong file

Advertisement

H.CH
Joined:
Posts:
1

Issue with external editor (.bat) for decrypting .gpg files – script receives wrong file

Hello,

I'm trying to use an external editor in WinSCP to decrypt .gpg files automatically using a batch script that calls GPG and opens the decrypted content in Notepad.

⚙️ My setup:
In WinSCP > Preferences > Editors:
  • Editor: C:\Users\h.chahid\Documents\Scripts\cmdgpg.bat
  • Arguments: %f
The batch script (cmdgpg.bat) looks like this:
@echo off
setlocal
 
if "%~1"=="" (
    echo No file specified.
    pause
    exit /b
)
 
set "encrypted_file=%~1"
set "output_file=%TEMP%\decrypted.txt"
 
"C:\Users\h.chahid\AppData\Local\Programs\GnuPG\bin\gpg.exe" --yes --batch --output "%output_file%" --decrypt "%encrypted_file%"
 
if exist "%output_file%" (
    start notepad "%output_file%"
) else (
    echo ❌ Failed to decrypt.
    pause
)
❌ The issue:

When I double-click a .gpg file in WinSCP, I get this error:
gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: Unknown system error
After checking logs, I realized that the script is sometimes receiving its own path instead of the actual .gpg file.
This causes the script to try and decrypt itself, not the target file.
✅ What I’ve tried:
  • Setting %f in the parameters field (with quotes)
  • Changing FTP mode (active/passive)
  • Enabling detailed logs
  • Verifying that the file is valid OpenPGP
  • Manually decrypting the file via GPG (works perfectly)
❓My question:
  • Why does WinSCP sometimes pass the wrong file to the script?
  • Is there a better way to reliably pass the actual .gpg file path to a custom .bat editor?
  • Could this be an issue related to FTP file handling or how WinSCP creates temporary files?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
42,146
Location:
Prague, Czechia

Re: Issue with external editor (.bat) for decrypting .gpg files – script receives wrong file

There's nothing like %f in WinSCP.
The pattern to specify filename is !.!:
https://winscp.net/eng/docs/ui_editor_preferences#type

Also in general, for this type of task, custom command seems like the appropriate solution, not abusing external editor functionality (while it should work technically).
https://winscp.net/eng/docs/custom_command

Reply with quote

Advertisement

You can post new topics in this forum