I need to get the size of a folder (including all it's sub-folders).
I've tried:
use Net::FTP;
my $username=xyz;
my $password=abcd;
my $directory="\temp";
$ftp = Net::FTP->new("servername") or die "Can't connect: $@\n";
$ftp->login($username, $password) or die "Couldn't login\n";
$dir_size=$ftp->size($directory) or die "Couldn't get directory size\n"
$ftp->quit() or warn "Couldn't quit.\n";
print "Size: $dir_size\n";
But it fails at the "Couldn't get directory size".
However, it works if i try size on a file: $file_size=$ftp->size($filename) or die "Couldn't get $filename size\n";
The man page for Net::FTP indicates you can only do a $ftp->size($filename) on a file not a directory.
I need to be able to get the directory size - any idea's how?
#!perl -w
use Net::FTP;
use strict;
use CGI qw/:standard/;
print header,start_html;
my $username='yourname';
my $password='yourpass';
my $directory='/public_html';
my $ftp = Net::FTP->new('yourhost') or die "Can't connect: $@\n";
$ftp->login($username, $password) or die "Couldn't login\n";
$ftp->cwd($directory);
my @ls = $ftp->ls();
my $dir_size = '0';
for(@ls) {
my $size = $ftp->size($_) or next;
$dir_size+=$size;
print "$_ ($size)<br>\n";
}
$ftp->quit() or warn "Couldn't quit.\n";
print "Total Size: $dir_size\n";
print end_html;