#!/usr/local/bin/perl use strict; use Net::Telnet (); ### Season to taste my $tn = Net::Telnet->new(Timeout => 15, Prompt => '\>'); my $host = 'not.arealsite.net'; my $login = 'login'; my $passwd = 'passwd'; $tn->open($host); $tn->login($login, $passwd); my $msg = $tn->errmsg; if ($msg) { print "A system error was generated on the login attempt:\n"; print " '$msg'\n\n"; } ### Execute the remote script that creates the file we want to ftp my @list = $tn->cmd("./somescript.pl"); my $msg = $tn->errmsg; if ($msg) { print "An error occurred when executing cmd './somescript.pl':\n"; print " '$msg'\n\n"; } chomp @list; if ($list[0]) { print "*** The following message was return from HOST: '$host'\n"; foreach my $rec (@list) { print "$rec\n"; exit; } } ### close telnet connection my $ok = $tn->close; if (not $ok) { print "\n\n\nUnable to close Telnet connection to HOST: $host\n\n\n"; exit; } use Net::FTP; my $ftp = Net::FTP->new($host); my $RC = $ftp->login($login, $passwd); if (not $RC) { print "\n\nFTP Login to Remote Host: '$host' failed!\n\n"; print "No files updated from Remote host: '$host'!\n\n"; exit; } ### Delete old local copy of file to be ftp'd my $infile = "target.dat"; if (-e $infile) { unlink $infile; } ### Get new copy of remote file $RC = $ftp->get($infile); if (not $RC) { print "\n\nget command for remote file: '$infile' failed!\n"; print "No files updated from Remote host: '$host'.\n\n"; exit; } ### close ftp connection $ftp->quit;