Compress, Encrypt, Split and Transport Big Files Safely

by Ramesh Natarajan on April 6, 2009

Encrypt and Attach Big Files to Email AttachmentsEmail administrators may set a limit on the maximum attachment size that can be attached to an email. You can follow the steps mentioned below to transfer big files that cannot be attached to the email because of the attachment size restriction.

This technique can be used in general whenever you need to split huge files, encrypt and transfer it.

Following steps need to be followed on the sender side, for transporting the huge files safely and easily.

  1. Compress and optionally encrypt.
  2. Split & Send.


Following steps need to be followed on the receiver side:

  1. Receive & Join
  2. Uncompress

I. Steps Performed by the Sender

1. Compress the files and optionally encrypt it.

I prefer compression through zip, as it can be uncompressed in Windows also. If the receiver is
a windows user, he can unzip it without searching for a Linux server.

How to compress single file using zip ?

Syntax: $ zip output-file.zip input-file


How to compress multiple files using zip ?

Syntax: $ zip output-file.zip input-file1 input-file2 input-file3 ...


How to compress a directory using zip ?

Syntax: $ zip -r output-file.zip input-dir-name


How to encrypt the files while compressing ?

Syntax: $ zip -e output-file.zip intput-file

If the file contains sensitive information, you can encrypt the file while compressing it. Option -e encrypts the file with the given password, and the receiver should know this password for decrypting it. If the file size exceeds the specified limit after compressing also, then split the files as mentioned in the step 2.

2. Split the huge files

If the mail server’s maximum attachment size is 5 MB then split the files as mentioned below. This will split the huge file.txt into multiple 5MB files, which will be named as xaa, xab, xac and xad.

$ split --bytes=5M file.txt

$ ls -lh
-rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xaa
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xab
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 xac
-rw------- 1 ramesh programmers 128K Apr 2 18:54 xad


When you want to set custom name, then use the split command with PREFIX option as shown below. In the example below, the PREFIX is set to split_. So, the output files will be created as split_aa, split_ab, split_ac etc.,

Syntax: $ split --bytes=5M file PREFIX
$ split --bytes=5M file.txt split_

$ ls -lh
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_aa
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ab
-rw------- 1 ramesh programmers 5.0M Apr 2 18:54 split_ac
-rw------- 1 ramesh programmers 128K Apr 2 18:54 split_ad
-rw------- 1 ramesh programmers 15.2M Apr 2 13:13 file.txt


After the big file is split, you can attach these individual small files as email attachments. If you are a thunderbird user you can use Vim editor to compose email as we discussed earlier.

II. Steps Performed by the Receiver

1. Receive & Join the files

Once the receiver receives the email, joining these small files is very simple as shown below. ? is a shell meta character which matches any single character, so as we have xaa, xab, xac, and xad files get concatenated to the outfile.txt.zip.

$ cat xa? > outfile.txt.zip

(or)

$ cat split_a? > outfile.txt.zip

2. Uncompress the files

After joining these file you can uncompress it as shown below. It will uncompress and places the files in the current directory.

Syntax: $ unzip outfile.txt.zip


If the file is compressed and encrypted, unzip will ask for the password to decrypt the file as shown below. After giving the right password it will decrypt and uncompresses the files in the current directory.

$ unzip outfile.txt.zip
[outfile.txt.zip] 01.txt password:
Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

If you enjoyed this article, you might also like..

  1. 15 Awesome Examples to Manipulate Audio Files Using Sound eXchange (SoX)
  2. How To Send an Email With Attachment and Body from Linux
  3. How To Rename Multiple Files Together in Linux Using 3 Methods
  4. 10 Awesome Examples for Viewing Huge Log Files in Unix
  5. How To Convert Files To Different Formats Without Using Software
  

Vim 101 Hacks Book

{ 2 trackbacks }

I Have Candy, Get in The Van. - Nullamatix - Technology Made Simple
April 19, 2009 at 6:33 pm
I Have Candy, Get in The Van.
October 17, 2009 at 7:36 pm

{ 6 comments… read them below or add one }

1 Fran April 6, 2009 at 3:20 pm

Thank you for the tip.

2 VonSkippy April 8, 2009 at 5:10 pm

Sending large files via Email is HUGELY inefficient. Use a free service like FileFactory or YouSendIT (or course compression and encryption is a good idea).

3 Ramesh April 9, 2009 at 8:28 am

@VonSkippy,

I agree that sending large files via Email is not efficient.. Sometimes for some unavoidable reasons (some stupid corporate policies? or, digitally sign a huge document and send it? ) you may have to transfer large files over email.

4 Marci April 29, 2009 at 3:54 am

Useful tips. Thanks.

5 tehno April 30, 2009 at 1:32 pm

why dont you mention ftp/scp/ puttySCP or WinSCP ? It is secure, easy and efficient…

6 Ramesh Natarajan April 30, 2009 at 6:07 pm

@Marci,
Thanks for the comments. We are glad that you found this tips useful.
 
@Techno,
In the list you’ve provided, except FTP, everything else is definitely a secure way to transfer big files. The focus of this article was primarily to show how to split big files, transfer the split files and combine the split files at the receiver end.

Leave a Comment

Previous post:

Next post: