Net::FTP will allow you to deal with FTP sessions.
You can't FTP to a machine that isn't running an FTP server.
I'm not sure if it's possible to check for the status returned when FTP commands fail - I'm pretty sure it is possible, but I'd have to RTFM.
Your question is rather unclear - are you trying to connect to a remote box and carry out an FTP transaction, or are you trying to monitor a system locally by FTP'ing to yourself and/or run a command like 'top' or 'ps'?
Update: Thinking about this, some well placed error checking (eval statements? Don't quote me on that) should let you know if the initial connection attempt to the FTP server failled...
| [reply] |
| [reply] |
Here's something basic that should work. It will save the output of a ps -ef command to a file then use a regex to search if ftpd is running.
#!/usr/bin/perl -w
use strict;
# See if ftp is running
my $result;
my $file = "/tmp/df";
my $cmd1 = "ps -ef";
# Run the ps -ef command
$result = `$cmd1 >$file`;
# Open the file and search if the daemon is running
open (FILE, $file) or die "can't open $file: $!";
while (<FILE>){
if (/ftpd/){
print "The ftp daemon is running\n";
}
}
HTP
-Dru
Another satisfied monk.
| [reply] [d/l] |
Perl can execute UNIX commands doing something that took me forever to figure out and is just really weird.
I couldn't pray to tell you where to find it anymore but here is the answer. I could let you look for it forever HAHAHA! but I'm nice.
#!/usr/bin/perl -w
open I, "| ps -ef" or die;
close I;
Now remember where it says "open I"....."I" can be anything. It could be "Open PROCESS" it doesn't matter. The "close I" has to be there though or "close PROCESS". You can make that handle anything you want it to be.
Then after that you can use any UNIX system command.
ls, cd, ls -al, ftp, it will open anything so far as I've used it.
HAVE FUN!
The Brassmon_k | [reply] [d/l] |
brassmon_k, you are referring to opening a pipe to read process output. Unfortunately the syntax you suggest is the one for *supplying input* to the subprocess, which is not a common usage of pipes (your pipe character is the *first* character of the command).
Far more common is to run a command producing output which the perl code must process, using the pipe character ('|') as the *last* character of the command (e.g., open PH, "shell command|".).
Sample code follows:
open PH, "ps -ef|" or die "$!: opening pipe";
while (<PH>) { # retrieves output from "ps" command one line at a ti
+me
# .. process output--each line is $_ ..
}
close PH or die "$!: error closing pipe";
dmm
You can give a man a fish and feed him for a day ...
Or, you can teach him to fish and feed him for a lifetime
| [reply] [d/l] [select] |
What do you mean?
I tested the little Perl snippet on my SPARC and it produces the output on STDOUT for the "ps -ef" command.
I don't get what you mean for "standard input". I know the handle is used for INPUT processing via a file Handle but what I suggested still works.
It's probably not syntaticallly correct but it works perfect. Perl doesn't seem to care if the pipe (|) is in front.
It does send the "ps -ef" command to STDOUT though I guarantee it...try it.
I also found it convienient to give it a handle because then this guy can manipulate the data any way he wants to later on.
I might be misunderstanding you though.
The Brassmon_k
| [reply] |