Encrypt zip file in folder with PGP - encryption

I have been testing with PGP command line to create a batch file that encrypts all zip files in a folder
So far I have tried
GPG -e -r username c:\foldername*.zip
But when I run the bat file nothing happens.
Do I need the path to where PGP is installed adding?
I would also like to delete the zip once it’s encrypted and on a previous batch file used -SDEL, will this work here
Thanks

gpg doesn't seem to work file wildcards. You should use for cycle, see this answer for the examples: How to do something to each file in a directory with a batch script

Related

Winzip command line - Include full path information

How do I use winzip command line with include full path information ? I know I can do this under Winzip GUI but how to do it using cmd ? Also, is there a way to zip selected specific folders only ? Thanks
Tried GUI and it is working very slow
Winzip command line doesnt seem to zip selected folders - either parent folders or specific subfolders
I am using winzip 27 command line and this is the syntax I am using:
wzzip -a -e0 -k -P -r -yx "C:\Users\source\to\save\zipfile.zip" "C:\example"
This stores files and folder timestamps underneath C:\example. But since I have enabled -P -r, I want to store the timestamps of the upper folder, C:\example folder. How can I do that ? Does anyone have suggestions?
Also, how do I specify the path for a mapped network drive? Thanks!

zip command in unix with wildcards

I am trying to zip file which is in the format of Amazon*.xls in unix and also remove the source file after compression.Below is the used command
zip -m Amazon`date +%Y-%m-%d:%H:%M:%S`.zip Amazon*.xls
For the above command i am getting below error
zip I/O error: No such file or directory
zip error: Could not create output file Amazon.zip
PS: GZIP is working fine. I need zip format files.
It is not the zip, it is how your shell deals with expanding/substituting variables. Two lines solution for bash
export mydate=`date +%Y-%m-%d:%H:%M:%S`
zip -m Amazon_$mydate.zip *matrix*
Execute by hand (few secs difference) or better put in a shell script myzipper.sh and just source it.
Use '-p' instead of '-m', if zip files are to be extracted on Windows OS.
export mydate=date +%Y-%m-%d:%H:%M:%S
zip -p Amazon_$mydate.zip matrix

7zip - zip and encrypt entire directory of folders

I am using the below code to batch zip an entire directory of folders.
for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\"
Is there a way to incorporate an encryption option to this? I would like to add a unique password to each zip output file.

Compress a file with password- encryption not supported

I am going to compress some .csv file in one file, but I have to set password for this.
I have used zip -P password file.zip myfiles
but it gives me an error...
zip error: Invalid command arguments (encryption not supported)
I am working on Solaris machine.
Could someone help me about this?
I found the way
7z a -p[password] -r Fdirectory.7z /path/to/F

Compress and encrypt multiple files individually while preserving the file structure

I have several directories that look like this:
dir1/
|_foo.txt
|_bar.txt
dir2/
|_qux.txt
|_bar.txt
For each of this directory I want to compress the files inside it into some encrypted format
then copy the structure to a new location (somewhere online). So finally we hope to get something like this in the new location:
dir1/
|_foo.rar
|_bar.rar
dir2/
|_qux.rar
|_bar.rar
Is there a simple Unix way to do it?
P.S. I was looking a rar for the encrypted and compressed files but if there is anything better let me know.
EDIT: In case I wasn't clear, this is for backup purposes.
Here is how I would do it.
First, create this helper script and put it somewhere. I put mine in /Users/martin/1temp/stackoverflow/26960080/encrypt-and-compress.sh. Don't forget to make it executable with chmod +x, and don't forget to update the paths to make them match your system. Note the file temp-password-for-batch-encryption.txt which is a simple text file with one line with the password used for encryption. Without this file you have to manually enter the password for each file encrypted, which quickly becomes a bore. Be careful with who has access to read that file though.
#!/bin/bash
# The relative path of the file to encrypt, passed as a parameter by find
file_to_encrypt="$1"
# The directory where the mirrored, encrypted directory structure shall end up
dest_dir="$HOME/1temp/stackoverflow/26960080/result-dir"
# Relative path to the dir of the file to encrypt, used to create the
# same directory structure elsewhere
dir_of_file_to_encrypt="$(dirname ${file_to_encrypt})"
# In what dir to put the result file, used to be able to create that
# dir before we encrypt the file
dest_dir_of_file_to_encrypt="${dest_dir}/${dir_of_file_to_encrypt}"
# Path to where the encrypted file shall be put
dest_file="${dest_dir}/${file_to_encrypt}"
# To not have to input the password manually each time, put it in this
# file temporarily (make sure to now allow anywone else to access this
# file...)
password_file="$HOME/1temp/stackoverflow/26960080/temp-password-for-batch-encryption.txt"
# Make sure the dest dir exists
mkdir -p "${dest_dir_of_file_to_encrypt}"
echo "About to encrypt ${file_to_encrypt} and putting it in ${dest_file} using password in ${password_file}"
# Encrypt the file and put it in the dest dir
# --symetric: Use simple so called symmetric encryption
# --cipher-algo: Select encryption algorithm
# --passphrase-fd 0: make "password from a file" work
# --yes: Overwrite any existing files
cat "${password_file}" | gpg --symmetric --cipher-algo AES256 --passphrase-fd 0 --yes --output "${dest_file}" "${file_to_encrypt}"
Then, cd into the root of the directory structure you want to encrypt.
cd /Users/martin/1temp/stackoverflow/26960080/input-dir/
Then run the script for each file using find, like this:
find . -type f -exec /Users/martin/1temp/stackoverflow/26960080/encrypt-and-compress.sh {} \;
This will mirror the input-dir tree to result-dir. To decrypt a file, use:
gpg --decrypt /Users/martin/1temp/stackoverflow/26960080/result-dir/./dir1/foo.txt
To mirror the resulting encrypted directory structure, I suggest you use rsync. The specifics depends a lot on the setup you have/want, but it's pretty easy to google.
Good luck!

Resources