LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2019, 05:13 AM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Rep: Reputation: Disabled
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.
 
Old 08-12-2019, 05:58 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,000

Rep: Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098Reputation: 4098
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.
 
Old 08-12-2019, 10:29 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,846

Rep: Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321Reputation: 1321
Guess it would be a "tar -czf - ... | ssh ... 'tar -xzf -'" pipeline, called with system(3).
 
Old 08-12-2019, 11:32 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 21,828

Rep: Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783Reputation: 5783
Quote:
Originally Posted by shamjs View Post
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.
 
Old 08-26-2019, 06:40 AM   #5
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
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..

Last edited by shamjs; 08-26-2019 at 06:41 AM.
 
Old 08-26-2019, 06:46 AM   #6
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
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..
 
Old 08-26-2019, 08:09 AM   #7
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,033

Rep: Reputation: 561Reputation: 561Reputation: 561Reputation: 561Reputation: 561Reputation: 561
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
 
Old 08-26-2019, 08:58 AM   #8
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
In my case the files will not be altered while taring the folder.
 
Old 08-26-2019, 10:38 AM   #9
Contrapak
Member
 
Registered: May 2019
Location: /home/
Distribution: Arch Linux
Posts: 131

Rep: Reputation: 51
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;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
want to 'tar' a folder without some contents of folder shipon_97 Linux - Newbie 5 10-13-2007 04:21 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
How do I un tar a .tar, .tar.z, .tar.gz file vofkid Linux - Newbie 4 03-15-2002 02:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration