Email 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.
- Compress and optionally encrypt.
- Split & Send.
Following steps need to be followed on the receiver side:
- Receive & Join
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: