简体   繁体   中英

Transfer compressed files over a socket?

I have 2 computers. One (computer 2) is getting files (.json) from 2 different processes, and then it passes this files (through ethernet cable) to the other computer (computer 1) (like in the attached image). This happens constantly not just one's.

To do this file transfers, my idea is the following:

  • Create a server/client sockets in c to comunicate both computers.
  • Tar the files (an amount say 4 files) in computer 2.
  • Recive the files in computer 1.

One way at first I wanted to do this, was with Netcat and tar, in bash. But the I read that it was not a good Ideas, because bash doesn't work well with file transfers. So I decided to do it in C (it has to be C, or C++, not python, but I am better at C so C is the option). So now I am doing it with this sample code:

Send and Receive a file in socket programming in Linux with C/C++ (GCC/G++)

but I cant figure out the part of tar and sending Tar, and if this code would help for this.

Other way I wa thinking to do it was with zeromq, but I havent use this before, so I dont know if it is worth the extra studding.

Thanks a lot in advance for your answers.

image

The .tar file format is pretty straightforward (and documentation on how to read/write a .tar file yourself can be found via a Google search on ".tar file format" or similar), or you could just use the existing libtar reader/writer library if you'd prefer not to reinvent the wheel.

Another alternative (assuming you just need a quick program to handle a personal use-case and don't need a production-grade solution) would just be to call system () (or similar) to have it execute the appropriate shell commands on behalf of your C program -- but if that's good enough, one has to wonder why a simple bash script isn't also acceptable. Bash may not be good at file transfers natively, but the various command-line utilities you can call from bash (scp, rsync, tar, untar, etc) certainly work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM