Page 1 of 1

GPG encrypt file batch script - nearly their!

Posted: 07 Oct 2010 17:45
by Imtryin
SETLOCAL
PATH=C:\Program Files (x86)\GNU\GnuPG;%PATH%
>"%TMP%\~encryptlist.txt" DIR /B "C:\outgoingdropfolder"
PUSHD "C:\outgoingdropfolder"
FOR /F "delims=" %%F IN ('MORE ^< "%TMP%\~encryptlist.txt"') DO (
IF EXIST %%F (
ECHO bingos| GPG --batch -se --passphrase-fd 0 -r PGPTOKEY -o "C:\encryptedfiles\%F.pgp"
IF ERRORLEVEL == 0 DEL "%%F"
)
)
POPD
DEL "%TMP%\~encryptlist.txt"
ENDLOCAL

above is the script im using to try and automate GPG the above is working sort off

let me explain what i want it to do

a User can drop any type of file, called anything they like into the dropfolder, when the batch runs, i want the file (or files) to be encrypted (all with the same encryption and signing key) and then outputted to the folder called encrypted files, the file names must be the same as they were when they went in, except obviousley the new pgp extension. (i require the output to be a PGP extension)

This is what happens when i run the above batch.

I drop a file called lee.txt (10mb) into dropfolder, run the batch, the file dissapears from drop folder, and appears in the encypted files folder with the file name f.PGP ? and is only 1kb in size ?

the encryptlist.txt appears to be working fine. Im hoping that it will be able to handle more than one file ( I asume that is what the encrypt list is for ?
) however im unable to confirm as the files are becoming over written when they get to encrypted folder. If i drop 2 files at the same time then the encrypted list does pick up 2 different file names.

I can confirm that encyption and signing is working as it should, i can suucesfully decypt and verify signature using PGP, (but like i said, the file is empty)

Hope ive explained clearly enough, thanks to all that have helped me get to this stage.

Lee

Re: GPG encrypt file batch script - nearly their!

Posted: 08 Oct 2010 14:25
by aGerman
I have no idea about the command line options of GnuGP. Please find out by yourself.

It makes no sense to write a temporary file if you could process the output of DIR directly.
'IF ERRORLEVEL == 0' will never work and 'IF %ERRORLEVEL% == 0' would not work into a FOR loop.
'-o "C:\encryptedfiles\%F.pgp"' sounds like the output file, but IMO the input file is missing?! And why '%F.pgp' instead of '%%F.pgp'?

Maybe this would work:

Code: Select all

SETLOCAL
PATH=C:\Program Files (x86)\GNU\GnuPG;%PATH%
PUSHD "C:\outgoingdropfolder" ||GOTO :eof
FOR /f "delims=" %%F IN ('DIR /a-d /b') DO (
  (ECHO bingos| GPG --batch -se --passphrase-fd 0 -r PGPTOKEY -o "C:\encryptedfiles\%%~F.pgp" "%%~F") &&DEL "%%~F"
)
POPD
ENDLOCAL


Regards
aGerman