NAME

Filesys::SmbClientParser - Perl client to reach Samba ressources

SYNOPSIS

use Filesys::SmbClientParser;
my $smb = new Filesys::SmbClientParser;

# Set parameters for connect
$smb->User('Administrateur');
$smb->Password('password');
# Or like -A parameters:
$smb->$auth("/home/alian/.smbpasswd");

# Set host
$smb->Host('jupiter');

# List host available on this network machine
my @l = $smb->GetHosts;
foreach (@l) {print $_->{name},"\t",$_->{comment},"\n";}

# List share disk available
my @l = $smb->GetShr;
foreach (@l) {print $_->{name},"\n";}

# Choose a shared disk
$smb->Share('games2');

# List content
my @l = $smb->dir;
foreach (@l) {print $_->{name},"\n";}

# Send a Winpopup message
$smb->sendWinpopupMessage('jupiter',"Hello world !");

# File manipulation
$smb->cd('jdk1.1.8');
$smb->get("COPYRIGHT");
$smb->mkdir('tata');
$smb->cd('tata');
$smb->put("COPYRIGHT");
$smb->del("COPYRIGHT");
$smb->cd('..');
$smb->rmdir('tata');

# Archive method
$smb->tar('c','/tmp/jdk.tar');
$smb->cd('..');
$smb->mkdir('tatz');
$smb->cd('tatz');
$smb->tar('x','/tmp/jdk.tar');

DESCRIPTION

SmbClientParser work with output of bin smbclient, so it doesn't work on win platform. (but query of win platform work of course)

A best method is work with a samba shared librarie and xs language, but on Nov.2000 (Samba version prior to 2.0.8) there is no public interface and shared library defined in Samba projet.

Request has been submit and accepted on Samba-technical mailing list, so a new module with name SmbClient will be done as soon as the public interface has been known.

For Samba client prior to 2.0.8, use this module !

SmbClientParser is adapted from SMB.pm make by Remco van Mook mook@cs.utwente.nl on smb2www project.

AUTHOR

Alain BARBET alian@alianwebserver.com

SEE ALSO

smbclient(1) man pages.

DESCRIPTION

Objects methods

new([$path_of_smbclient])
Host($hostname)

Set the remote host to be used to $hostname.

User($username)

Set the username to be used to $username.

Share($sharename)

Set the share to be used on the remote host to $sharename.

Password($password)

Set the password to be used to log on to the remote share $password.

Debug($debug)

Set the debug verbosity

0 = no output
1+ = more output
Auth($auth_file)

Use the file $auth_file for username and password. This uses User and Password instead of -A to be backwards compatible.

Network methods

GetShr

Return an array with sorted share listing

Syntax: @output = $smb->GetShr

array contains hashes; keys: name, type, comment

GetHosts

Return an array with sorted host listing

Syntax: @output = $smb->GetHosts

array contains hashes; keys: name, comment

sendWinpopupMessage($dest,$text)

This method allows you to send messages, using the "WinPopup" protocol, to another computer. If the receiving computer is running WinPopup the user will receive the message and probably a beep. If they are not running WinPopup the message will be lost, and no error message will occur.

The message is also automatically truncated if the message is over 1600 bytes, as this is the limit of the protocol.

Parameters :

$dest: name of host or user to send message
$text: text to send

Operations

cd [$dir]

cd [directory name] If "directory name" is specified, the current working directory on the server will be changed to the directory specified. This operation will fail if for any reason the specified directory is inaccessible. Return list.

If no directory name is specified, the current working directory on the server will be reported.

dir

Return an array with sorted dir and filelisting

Syntax: @output = $smb->dir (host,share,dir,user,pass)

Array contains hashes; keys: name, attr, size, date

mkdir($masq)

mkdir <mask> Create a new directory on the server (user access privileges permitting) with the specified name.

rmdir($masq)

Remove the specified directory (user access privileges permitting) from the server.

get($file, $target, [$dir])

Gets the file $file, using $user and $pass, to $target on courant SMB server and return the error code. If $target is unspecified, courant directory will be used For use STDOUT, set target to '-'.

Syntax: $error = $smb->get ($file,$target,[$dir])

mget($file,[$recurse])

Gets file(s) $file on current SMB server,directory and return the error code. If multiple file, push an array ref as first parameter or pattern * or file separated by space

Syntax:

$error = $smb->mget ('file'); #or
$error = $smb->mget (join(' ',@file); #or
$error = $smb->mget (\@file); #or
$error = $smb->mget ("*",1);
put$($orig,$file,[$dir])

Puts the file $orig to $file, using $user and $pass on courant SMB server and return the error code. If $orig is unspecified, STDIN is used (-).

Syntax: $error = $smb->PutFile ($host,$share,$file,$user,$pass,$orig)

mput($file,[$recurse])

Puts file(s) $file on current SMB server,directory and return the error code. If multiple file, push an array ref as first parameter or pattern * or file separated by space

Syntax:

$error = $smb->mput ('file'); #or
$error = $smb->mput (join(' ',@file); #or
$error = $smb->mput (\@file); #or
$error = $smb->mput ("*",1);
del($mask)

del <mask> The client will request that the server attempt to delete all files matching "mask" from the current working directory on the server

rename($source, $target)

rename source target The file matched by mask will be moved to target. These names can be in differnet directories. It returns a return value.

pwd()

pwd Returns the present working directory on the remote system. If there is an error it returns undef.

Archives methods

tar($command,$target)

Execute TAR commande on //$host/$share/$dir, using $user and $pass, to $target. and return the error code. If $target is unspecified, current directory will be used.

Syntax: $error = $smb->tar ($command) where command in ('x','c',...) See smbclient man page

Private methods

byname

sort an array of hashes by $_->{name} (for GetSMBDir et al)

operation(...)
command($args,$command)