Hey guys,
I'm trying to write a perl socket daemon that will listen on a port and accepts a data connection via a tar piped with netcat for backups. The client will run this command:
my perl code is here:
I do get output written as backup.tar in the desired path but it's raw data and not a tar archive. Can someone shed me some light on this? Thank you.
-twan
I'm trying to write a perl socket daemon that will listen on a port and accepts a data connection via a tar piped with netcat for backups. The client will run this command:
Code:
tar cvf - tartest | nc 192.168.1.10 9999
my perl code is here:
Code:
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my $client;
my $socket;
my $file;
my $logfile;
my $line;
my $buf;
my $host;
# Supply argument...
if (@ARGV != 1) {
die "Need to supply an argument\nUsage: $0 port\n"
}
my $port=$ARGV[0];
# Setup the socket...
$socket = IO::Socket::INET->new(
"Proto" => "tcp",
"LocalPort" => $port,
"Listen" => 1) or die "ERROR: $!\n";
print "Waiting for connection...\n";
# Accept the connection...
while ($client=$socket->accept()) {
next if my $pid=fork;
die "Cannot fork $!\n" unless defined $pid;
$host=$client->peerhost();
print "Connection received from: ", $host . "\n";
$logfile = <$client>;
print "Backup File: $logfile";
# This is the part I need help on...
while (defined($buf=<$client>)) {
open(BKUP, ">/tmp/$host/backup.tar") or die "Cannot write to /tmp $!";
print BKUP $buf;
close(BKUP);
}
close $client;
I do get output written as backup.tar in the desired path but it's raw data and not a tar archive. Can someone shed me some light on this? Thank you.
-twan