#!/usr/bin/perl -wT -I../../..

use strict;

use Pos::Webtop::FileShare::Smb;

#use Pos::Webtop::Web::RequiredPerlModules;
#Pos::Webtop::Web::RequiredPerlModules::load();

my $printExtInfo = 0;
my $dirPath = '\\';
my $blockSize = 512;

print "Setting up connection to \\\\data.positivenetworks.net\\files\n";
my $share = Pos::Webtop::FileShare::Smb->new(
		shareUserName => "files",
		sharePassword => "sadfiles",
		serverName => "data",
		shareName => "files",
		ipAddress => "209.242.113.69"
);
die "Unable to create Pos::Webtop::FileShare::Smb object" unless defined $share;

print "Getting a directory listing for $dirPath:\n";
my $dirListing = $share->getDirListing( dirPath => $dirPath, getExtendedInfo => 1 );
die "Unable to get directory listing" unless defined $dirListing;

# Sort the directory listing first by name, then by item type
my @sortedDirListing = sort { $a->{'itemType'} cmp $b->{'itemType'} } (sort { uc($a->{'itemName'}) cmp uc($b->{'itemName'}) } @{$dirListing});

foreach my $item (@sortedDirListing)
{
	print $item->{'itemType'} . ": " . $item->{'itemName'} . " \t(Size: " . $item->{'itemBytes'} . " bytes) \t(Modified: " . $item->{'itemMtime'} . ")\n";

	if ( $printExtInfo ) {
		foreach my $key ( keys(%$item) )
		{
			if ( $key =~ /time/ )
			{
				print "$key -> " . localtime($item->{$key}) . "\n";
			}
			else
			{
				print "$key -> $item->{$key}\n";
			}
		}
	}
}

