Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to accomplish something rather simple (at least it would seem to be):

  1. Compress a directory
  2. Encrypt the compressed file
  3. Upload the compressed & encrypted file via FTP

I also want to accomplish this in an automated fashion on Linux server.

TrueCrypt is not really an option in this case as it seems it can't compress a single file. Instead you have to make a volume that you mount and move the files into.

This question answers how to do the the upload and I know how to compress a directory. It is just the encryption that's giving me problems.

share|improve this question
up vote 2 down vote accepted

I've used bcrypt for this pretty happily. Actually, I'm using gpg now. (Just checked, it's been that long since I automated the process involved. I don't recall why I switched, but I think it may have been that I felt gpg was easier to script.) My command line looks like this:

gpg -r RECIP --output OUTPUT_FILE_NAME --encrypt INPUT_FILE_NAME


  • RECIP is the name of the key I want to use (the -r is for "recipient;" gpg mostly started life as a means of encrypting email; don't let that bother you, it's general-purpose).
  • OUTPUT_FILE_NAME is the output (encrypted) file
  • INPUT_FILE_NAME is the input file (cleartext) file
share|improve this answer

Is there a particular reason that you have to use FTP? Because if not, then SCP is going to be a better option. First because it uses an encrypted channel to send the files (no cleartext passwords for Google StreetView cars to record :-), second because it can use private key authentication, and third because it's really meant for copying.

Regardless, tar is the standard way to create a single file out of a directory, and the -z switch will use GZIP compression.


Then you need to encrypt it. I use ccrypt, but there are other options. And maybe there are reasons not to use it that I don't know about.

ccrypt -k KEYFILE OUTFILE.tgz

Finally, copy it to your destination server. I'll assume that you have a "Transfer" directory under your home directory, and have set up private-key authentication.

scp OUTFILE.tgz.cpt YOURHOST:Transfer

If FTP really is a requirement, you can use curl to do the transfer. I've never done this myself (and have no FTP server with which to try it), but a quick read of the manpage indicates the following:

curl --upload-file OUTFILE.tgz.cpt -u USER:PASSWORD ftp:://YOURHOST/HOSTPATH
share|improve this answer
Yes, there is a reason I have to use FTP. ccrypt has no keys or are they created/stored separately? – Kristoffer L May 26 '10 at 6:47
Although the other answer seems to be what you want, I'll leave mine for someone else. I've edited to mention curl, and how to get a key from a file; man ccrypt will give you more info. – Anon May 26 '10 at 14:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.