Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

H.CH

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:

```bat
@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?