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
⚙️ My setup:
In WinSCP > Preferences > Editors:
❌ The issue:
When I double-click a .gpg file in WinSCP, I get this error:
This causes the script to try and decrypt itself, not the target file.
✅ What I’ve tried:
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
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 )
When I double-click a .gpg file in WinSCP, I get this error:
After checking logs, I realized that the script is sometimes receiving its own path instead of the actual .gpg file.gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: Unknown system error
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)
- 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?