Skip to content

Instantly share code, notes, and snippets.

@samuraitruong
Created April 19, 2020 23:02
Show Gist options
  • Save samuraitruong/59857c11b279e9301db670742f4ec5b2 to your computer and use it in GitHub Desktop.
Save samuraitruong/59857c11b279e9301db670742f4ec5b2 to your computer and use it in GitHub Desktop.
s3-2-sftp
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/% cfl_user@59.154.134.99:/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