Created
April 19, 2020 23:02
-
-
Save samuraitruong/59857c11b279e9301db670742f4ec5b2 to your computer and use it in GitHub Desktop.
s3-2-sftp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set e | |
s3_folder=s3://you-bucker/your-folder | |
sftp=user@IP:/FOLDER/ | |
GPG_KEY_NAME="GPG_KEY_NAME"; | |
rm -rf ./encrypted ./csvs ./zip | |
aws s3 cp $s3_folder ./csvs --recursive | |
mkdir ./zip || true | |
ls ./csvs | xargs -I % sh -c "zip -j ./zip/%.zip ./csvs/%" | |
echo "ZIP files" | |
ls ./zip | |
gpg --import GPG_KEY_NAME.asc | |
gpg --list-keys | |
mkdir ./encrypted || true | |
ls ./zip | xargs -I % sh -c "gpg --encrypt --armor --trust-model always --recipient $GPG_KEY_NAME --output ./encrypted/%.gpg ./zip/%" | |
echo "Encrypted folder " | |
ls ./encrypted | |
echo "Upload file to SFTP" | |
#ls ./encrypted | xargs -I % sh -c "scp -i /home/ec2-user/.ssh/id_rsa ./encrypted/% [email protected]:/PAYLOAD/" | |
ls ./encrypted | xargs -I % sh -c "sftp -vvv -oPort=22 -o \"IdentityFile=~/.ssh/id_rsa\" $sftp <<< $'put /path/encrypted/%'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment