#!/usr/bin/perl
#$Id: get_remote_data_socket.pl,v 1.2 2025/02/21 07:58:57 sqko Exp $
###########################################################################################
#
# Usage: ./get_remote_data_socket.pl $rig $host $port [@arguments to remote system]...
#
# Ex: ./get_remote_data_socket.pl 71 192.168.0.1 2020 get_data my_data_file
#
###########################################################################################
use strict;
use warnings;
use RFC::Rig;
use SocketClient;
my $rig = RFC::Rig->new(shift);
$rig->check_run();
my $date = localtime();
$date =~ s/\s/_/g;
my $fn = 'Remote_data_'.$date.'.txt';
my $file = $rig->webdir().$fn;
my $host = shift;
my $port = shift;
eval {
    die "Not enough arguments for $0" unless ($host && $port);
    my $data = socket_client_raw($host,$port,@ARGV);
    open MYOUT,'>',$file or die "Could not open file $file for writing: $!\n";
    print MYOUT $data;
    close MYOUT;
};
if ($@)
{
    warn $@,"\n";
    &errorlog($@);
}
