FTP stands for "File Transfer Protocol". It doesn't do shell
commands. For that you can look at Net::Telnet or (depending
on your concerns about security) Net::SSH or Net::SSH::Perl.
Of course, if security was a concern, you wouldn't be using
FTP anyway, you'd be using SFTP or SCP anyway (for which
those have Net::* modules also...) | [reply] |
Are you thinking about the SITE command? If so, Net::FTP does have a site() method.
| [reply] |
A few options:
- You might look into the documentation for Net::Cmd module. Documentation from the Net::FTP perldocs is sketchy at best:
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.
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.
- The second option is to use a combination of Net::FTP and Net::Telnet. I have done this successfully, but it does require that you have both ftp and telnet access to the host. Here is a sample program:
#!/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
| [reply] [d/l] [select] |