LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What is the efficient way to remotely copy a tar.gz file or a folder contents over a network in c++ programmatically (https://www.linuxquestions.org/questions/programming-9/what-is-the-efficient-way-to-remotely-copy-a-tar-gz-file-or-a-folder-contents-over-a-network-in-c-programmatically-4175659009/)

shamjs 08-12-2019 05:13 AM

What is the efficient way to remotely copy a tar.gz file or a folder contents over a network in c++ programmatically
 
Hi,

I need to copy an entire directory from one host to other programmatically in C++.

My directory contains different file types like .dlt .png etc..

I am ok with either

1. taring the entire directory and copy the tar file to a remote machine.

Or

2. copying the directory as such.

my directory size range between 400 to 500MB

Please throw some light on this, to proceed further.

Also i appreciate if you share some code snippets to achieve the same.

pan64 08-12-2019 05:58 AM

did you try to look for a solution on the net?
the language is more or less irrelevant, the implementation depends on your connection and connection type.
you can use scp, ftp, rsync, nfs, samba or something else.

NevemTeve 08-12-2019 10:29 AM

Guess it would be a "tar -czf - ... | ssh ... 'tar -xzf -'" pipeline, called with system(3).

TB0ne 08-12-2019 11:32 AM

Quote:

Originally Posted by shamjs (Post 6024302)
Hi,
I need to copy an entire directory from one host to other programmatically in C++.

My directory contains different file types like .dlt .png etc.. I am ok with either

1. taring the entire directory and copy the tar file to a remote machine.

Or

2. copying the directory as such.

my directory size range between 400 to 500MB Please throw some light on this, to proceed further. Also i appreciate if you share some code snippets to achieve the same.

After asking about programming for years now, it's odd that you need us to provide you with code. Here's a better suggestion: why don't YOU post the code that YOU have written, and tell us why it's giving you a problem? Read the "Question Guidelines"...we are happy to help, but we aren't going to do your work/homework for you. Show your efforts.

shamjs 08-26-2019 06:40 AM

Quote:

Originally Posted by TB0ne (Post 6024432)
After asking about programming for years now, it's odd that you need us to provide you with code. Here's a better suggestion: why don't YOU post the code that YOU have written, and tell us why it's giving you a problem? Read the "Question Guidelines"...we are happy to help, but we aren't going to do your work/homework for you. Show your efforts.



It was just a request that i made here to share the code snippet if any since i was unable to find a reference impl, anyhow no issues cool..

shamjs 08-26-2019 06:46 AM

https://github.com/KrishnaChaurasia/...-file-transfer

i just tweaked the above reference implementation as per my use case and it worked well. :)

thanks everyone here, for your inputs..

Firerat 08-26-2019 08:09 AM

something to consider
how likley is it that a file will change during the archive?
will it matter?

for instance files aaa.db and zzz.db are related in some way
aaa.db gets tared but by the time you reach zzz.db it has changed and effects aaa.db in some way.

one solution to this problem is snapshots, where the filesystem takes snapshot intime and you then transfer that snapshot without worring about file updates

shamjs 08-26-2019 08:58 AM

In my case the files will not be altered while taring the folder.

Contrapak 08-26-2019 10:38 AM

You could shorten yoru error handling from this:

Code:

fd=socket(AF_INET,SOCK_STREAM,0);
  if(fd<0){
  cout<<"Error creating socket\n";
  return 0;
}

Code:


if((fd=socket(AF_INET,SOCK_STREAM,0)) < 0) {
  cout<<"Error creating socket\n";
  return 0;
}



All times are GMT -5. The time now is 06:26 PM.