Friday, November 14, 2008

Perl FTP Test program - Net::FTP - useful for monitoring/ testing

The following is a Perl script that can be used to connect to and list an FTP directory.
This can be extended to accept the paremeters as required - host ip,user password, directory etc.
This also can be run in a loop or from cron to monitor connectivity or to monitor file movements(that is a not so good use!!)

use Net::FTP;
$host = '1x2.1xx.xx.xxx';
$user = 'User';
$pass = 'xxxxxxxxxxx';
$home = '/home/release;
print "Connecting...";
#connect
$ftp = Net::FTP->new($host);
#login
$ftp->login($user,$pass);
print "LoggedIn...";
#slurp
@result = $ftp->ls($home);
print "\nResult...";
for(@result)
{ print "\n";
print $_; }
$ftp->quit;
print "\n...Closed";

No comments: