in reply to Net::FTP - sending
Note the warning. Unfortunately, the Net::Cmd docs don't say how the commands are executed. I suspect (if anyone out there knows for sure, let me know) that it is using rsh to run the commands. This requires that the host you are accessing has rsh enabled, but on many systems it is disabled by sysadmins for security purposes.Methods for the adventurous "Net::FTP" inherits from "Net::Cmd" so methods defined in "Net::Cmd" + may be used to send commands to the remote FTP server. quot (CMD [,ARGS]) Send a command, that Net::FTP does not directly support, to the remote server and wait for a response. Returns most significant digit of the response code. WARNING This call should only be used on commands that do not require data connections. Misuse of this method can hang the connection.
#!/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;
--Jim
|
|---|