AUtomating an FTP Benchmark

Quick little script to automate an FTP test:

#!/usr/local/bin/perl
###
#waastest.pl
#ftp test procedure automation for waas
#v.099b - 2007.05.05 - Rich Bocchinfuso
#@COPYLEFT 2007 - MTI CTA Team - ALL WRONGS RESERVED
#requires: creatfil.exe ncftpget.exe ncftpput.exe
###

if ($ARGV[0] eq “-help”) {
&usage;
}
if ($ARGV[0] eq “-o”) {
&cmdparms;
}
else{
&menu;
}

sub menu {
&copyleft;
print “Enter target ftp host/ip (e.g. - 192.168.1.10): “
$target = <>
chomp $target;
print “Enter output filename: “
$output = <>
chomp $output;
print “Enter test description: “
$desc = <>
chomp $desc;
print “Enter starting file size in megabytes: “
$startmb = <>
chomp $startmb;
print “Enter ending file size in megabytes: “
$endmb = <>
chomp $endmb;
print “Enter incraments in megabytes: “
$incmb = <>
chomp $incmb;
print “Enter test type [p]ut, [g]et, [a]ll: “
$test = <>
chomp $test;
print “Enter username [e.g. - foo\@bar.com]: “
$user = <>
chomp $user;
print “Enter password: “
$password = <>
chomp $password;

&copyleft;
&beginstamp;
&convert;
if ($test eq “p” || $test eq “put”) {
&put;
}
if ($test eq “g” || $test eq “get”) {
&get;
}
if ($test eq “a” || $test eq “all”) {
&put;
&get
}
else{
&error;
}
&endstamp;
}

sub cmdparms {
$target=$ARGV[2];
$user=$ARGV[3];
$password=$ARGV[4];
$startmb=$ARGV[5];
$endmb=$ARGV[6];
$incmb=$ARGV[7];
$output=$ARGV[8];
$desc=$ARGV[9];
&copyleft;
&beginstamp;
&convert;
if ($ARGV[1] eq “-p”) {
&put;
}
if ($ARGV[1] eq “-g”) {
&get;
}
if ($ARGV[1] eq “-a”) {
&put;
&get;
}
&endstamp;
}

sub put {
open(LOG,”>>$output”) || die(”Can’t open output file: $!”);
print LOG “\n…initiating ftp PUT test…\n”
close (LOG);
for ($count = $start; $count <= $end; $count+=$inc) {
print “…creating $count byte file named file_$count.dat…\n”
system “creatfil file_$count.dat $count >> $output”
print “…putting $count byte file named file_$count.dat to $target…\n”
system “ncftpput -v -u $user -p $password $target . file_$count.dat 2>> $output”
print “…removing $count byte seed file named file_$count.dat…\n”
system “del file_$count.dat >> $output”
}
open(LOG,”>>$output”) || die(”Can’t open output file: $!”);
print LOG “…ftp PUT test complete…\n”
close (LOG);
}

sub get {
open(LOG,”>>$output”) || die(”Can’t open output file: $!”);
print LOG “\n…initiating ftp GET test…\n”
close (LOG);
for ($count = $start; $count <= $end; $count+=$inc) {
print “…getting $count byte file file_$count.dat from $target…\n”
system “ncftpget -v -u $user -p $password $target . file_$count.dat 2>> $output”
print “…removing $count byte file named file_$count.dat…\n”
system “del file_$count.dat >> $output”
}
open(LOG,”>>$output”) || die(”Can’t open output file: $!”);
print LOG “…ftp GET test complete…\n”
close (LOG);
}

sub convert {
# Convert MB to bytes
$start = $startmb*1024;
$end = $endmb *1024;
$inc = $incmb*1024;
}

sub beginstamp {
open(LOG,”>>$output”) || die(”Can’t open output file: $!”);
$datetime = localtime();
printf “WASS benchmark initiatied $datetime\n\n”
printf LOG “WASS benchmark initiatied $datetime\n”
print LOG “\nDescription: $desc\n\n”
close (LOG);
print “…testing and logging latency and packet loss…may take a minute…\n\n”
system “ping -n 10 -l 1024 $target >> $output”
}

sub endstamp {
open(LOG,”>>$output”) || die(”Can’t open output file: $!”);
$datetime = localtime();
printf “\nWASS benchmark completed $datetime\n\n”
printf LOG “\nWASS benchmark completed $datetime\n\n”
close (LOG);
}

sub copyleft {
system “cls”
print “\nWAAS FTP benchmark and test utility\n”
print “v.099 - 2007.05.05\n”
print “\@COPYLEFT 2007 - MTI CTA Team - ALL WRONGS RESERVED\n\n”
}

sub usage {
&copyleft;
print “\nUsage: waastest -help {…displays this help message}\n”
print “Usage: waastest {prompt based interface}\n\n”
print “Usage: waastest -o [command line parameters]\n”
print “waastest -o [-p | -g | -a] [target hostname/ip] [username] [password] [starting file size in MB] [ending file size in MB] [inrement by MB] [output log filename] [\"test description\"]\n”
print “-p … run put tests only\n”
print “-g … run get tests only\n”
print “-a … runs put and get tests\n”
exit;
}

sub error {
print “!error! !error!\n”
print “\”waastest -help\” - for usage instructions\n\n”
exit;
}

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 45 items have been purified.

buy viagra no rx
buy viagra online
buy viagra drugs
buy viagra test
buy viagra without prescription
buy viagra no doctor