#!/usr/bin/perl use strict; use warnings; use Net::EasyTCP; # Configuration settings our $host = 'myhost.mydomain.mytld'; our $port = 7716; our $password = 'secret passphrase or whatever'; # Implementation while (1) { print "Connecting to server...\n"; my $client = new Net::EasyTCP( mode => "client", host => $host, port => $port, ) || die "ERROR CREATING CLIENT: $@\n"; print "Connected. Sending get request...\n"; my $data = { password => $password }; $client->send($data) || die "ERROR SENDING: $@\n"; print "Sent. Reading reply...\n"; $data = $client->receive() || die "ERROR RECEIVING: $@\n"; unless (ref($data)) { print "Reply was: '$data', exiting\n"; $client->close(); exit(0); } # Note: Now we have the only copy of the file. # If we don't save it, it's lost. # Very simple sanity check, we trust the host... $data->{filename} =~ s!^.*/!!; if (-e $data->{filename}) { die "I won't overwrite '".$data->{filename}."'!\n"; } open F, '>', $data->{filename} or die $!; print F $data->{put}; close F or die $!; print "Written '".$data->{filename}."'.\n"; $client->close(); }