I am trying to compress a folder, encode to base64 and send it over the fly , but I am getting a error

tar: Cowardly refusing to create an empty archive

tar -czf Pictures | base64 | nc remote_host 443  

nc -lvp 443 | base64 -d > secret.tgz # remote host

how can I compres my folder and send it over the fly correctly?


The command is giving an error of "empty" archive because your are not passing it anything to tar for compressing.

When using -f what comes after should be the name of the archive to create and only then archives to compress (on your case, a directory).

For sending it to stdout to feed it to pipe, you should use the dummy option/shortcut "-"

As in:

tar -czf - Pictures | base64 | nc remote_host 443 

As also @muru correctly points out, tar output to stdout by default, so another option if taking out the "-f".

tar -cz Pictures | base64 | nc remote_host 443

nc also in theory is also well capable of handling binary files when not sending them to the console, you can do without the extra step of base64 enconding and decoding. I certainly did it thousands of times without using base64.

I would also prefer using the nc without -v for scripting in the remote side as in:

tar -czf - Pictures | nc remote_host 443  
nc -lp 443 > secret.tgz # remote host
| improve this answer | |
  • 1
    The f - is redundant; tar outputs to stdin by default if no output file is specified (so tar cz Pictures | ...) – muru Apr 15 '19 at 4:28
  • 1
    thanks so much for your help – yesii_0691 Apr 15 '19 at 4:29
  • 1
    @muru I know you mean stdout, thanks for pointing it out, and I prefer the notation of having - before arguments. – Rui F Ribeiro Apr 15 '19 at 4:31
  • 1
    @RuiFRibeiro ah, yes, typo. – muru Apr 15 '19 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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