|
各位使用perl的高手你們好:
本人想利用perl的程式來設計量測FTP下載檔案而得到的時間,應該會得到4個值(目前還沒有設計到這一步,而且也不太會,請求指導),現在是已設計到能connecftion到檔案了但是不能下載(這也是在板上學到的,真是謝謝),它是顯示"connection closed" 在程式上有些小錯誤,但是不知道要如何修正,煩請各位高手指導協助. 此程式是要能得到下載檔案的4個時間值然後配合mrtg然後得到圖形所做的程式,而且是要利用perl來設計,在此附上程式,請各位高手協助幫忙. 再次謝謝各位的幫忙
程式:因為ftp為私人架設所以不便公開,請見諒)
#!/usr/bin/perl
use Net::FTP;
my $host="ftp address";
my $directory="home";
my $file="file.rar";
$now = get_time();
sub get_time {
my ($sec,$min,$hour,$day,$mon,$year)=localtime(time);
$mon++;
if (length ($mon) == 1) {$mon = '0'.$mon;}
if (length ($day) == 1) {$day = '0'.$day;}
if (length ($hour) == 1) {$hour = '0'.$hour;}
if (length ($min) == 1) {$min = '0'.$min;}
if (length ($sec) == 1) {$sec = '0'.$sec;}
$year+=1900;
my $alltime="$year/$mon/$day $hourminsec";
}
print "$now\n";
$ftp=Net::FTP->new($host,Timeout=>240);
push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
myerr() if $newerr;
print "Connected\n";
$ftp->login("id","password");
print "Getting file list";
push @ERRORS, "Can't login to $host: $!\n" if $newerr;
$ftp->quit if $newerr;
myerr() if $newerr;
print "Logged in\n";
$ftp->cwd("/");
push @ERRORS, "Can't cd $!\n" if $newerr;
myerr() if $newerr;
$ftp->quit if $newerr;
@files=$ftp->dir;
push @ERRORS, "Can't get file list $!\n" if $newerr;
myerr() if $newerr;
print "Got file list\n";
foreach(@files) {
print "$_\n";
}
$ftp->quit;
sub myerr {
print "Error: \n";
print @ERRORS;
exit 0;
}
$ftp->get($file,$file) or die $ftp->message; |
|