NAME
Filesys::SmbClient - Interface for access Samba filesystem with libsmclient.so
SYNOPSIS
use POSIX;
use Filesys::SmbClient;
my $smb = new Filesys::SmbClient(username => "alian",
password => "speed",
workgroup => "alian",
debug => 10);
# Read a file
my $fd = $smb->open("smb://jupiter/doc/general.css", '0666');
while (defined(my $l= $smb->read($fd,50))) {print $l; }
$smb->close(fd);
# ...
There is some others examples in test.pl file
DESCRIPTION
Provide interface to access routine defined in libsmbclient.so.
On 2001/08/05, this library is available on Samba source, but is not build by default. (release 2.2.1). Do "make bin/libsmbclient.so" in sources directory of Samba to build this libraries. Then copy source/include/libsmbclient.h and source/bin/libsmbclient.so where you need them before install this module.
When a path is used, his scheme is :
smb://server/share/rep/doc
VERSION
$Revision: 0.6 $
FONCTIONS
- new(%hash)
-
Init connection Hash can have this keys:
username
password
workgroup
debug
Return instance of Filesys::SmbClient on succes, die with error else.
Example:
my $smb = new Filesys::SmbClient(username => "alian", password => "speed", workgroup => "alian", debug => 10);
Directory
- mkdir($fname,$mode)
-
Create directory $fname with permissions set to $mode. Return 1 on success, else 0 is return and errno and $! is set.
Example:
$smb->mkdir("smb://jupiter/doc/toto",'0666') || print "Error mkdir: ", $!, "\n";
- rmdir($fname)
-
Erase directory $fname. Return 1 on success, else 0 is return and errno and $! is set.
Example:
$smb->rmdir("smb://jupiter/doc/toto") || print "Error rmdir: ", $!, "\n";
- opendir($fname)
-
Open directory $fname and return file descriptor.
- readdir($fd)
-
Read a directory. In a list context, return the full content of the directory $fd, else return next element. Each elem is a name of a directory or files.
Return undef at end of directory.
Example:
my $fd = $smb->opendir("smb://jupiter/doc"); foreach my $n ($smb->readdir($fd)) {print $n,"\n";} close($fd);
- readdir_struct($fd)
-
Read a directory. In a list context, return the full content of the directory $fd, else return next element. Each element is a ref to an array with type and name. Type can be :
- SMBC_WORKGROUP
- SMBC_SERVER
- SMBC_FILE_SHARE
- SMBC_PRINTER_SHARE
- SMBC_COMMS_SHARE
- SMBC_IPC_SHARE
- SMBC_DIR
- SMBC_FILE
- SMBC_LINK
Return undef at end of directory.
Example:
my $fd = $smb->opendir("smb://jupiter/doc"); while (my $f = $smb->readdir_struct($fd)) { if ($f->[0] == SMBC_DIR) {print "Directory ",$f->[1],"\n";} elsif ($f->[0] == SMBC_FILE) {print "File ",$f->[1],"\n";} # ... } close($fd);
- closedir($fd)
-
Close directory $fd.
Files
- stat($fname)
-
Stat a file to get info via file $fname. Return a list with info on success, else an empty list is return and $! is set.
List is made with:
device
inode
protection
number of hard links
user ID of owner
group ID of owner
device type (if inode device)
total size, in bytes
blocksize for filesystem I/O
number of blocks allocated
time of last access
time of last modification
time of last change
Example:
my @tab = $smb->stat("smb://jupiter/doc/tata"); if ($#tab == 0) { print "Erreur in stat:", $!, "\n"; } else { for (10..12) {$tab[$_] = localtime($tab[$_]);} print join("\n",@tab); }
- fstat($fd)
-
Like stat, but on a file descriptor
- rename($oname,$nname)
-
Rename $oname in $nname. Return 1 on success, else 0 is return and errno and $! is set.
Example:
$smb->rename("smb://jupiter/doc/toto","smb://jupiter/doc/tata") || print "Can't rename file:", $!, "\n";
- unlink($fname)
-
Unlink $fname. Return 1 on success, else 0 is return and errno and $! is set.
Example:
$smb->unlink("smb://jupiter/doc/test") || print "Can't unlink file:", $!, "\n";
- open($fname, $mode)
-
Open file $fname with perm $mode. Return file descriptor on success, else 0 is return and $! is set.
Example:
my $fd = $smb->open("smb://jupiter/doc/test", 0666) || print "Can't read file:", $!, "\n"; my $fd = $smb->open(">smb://jupiter/doc/test", 0666) || print "Can't create file:", $!, "\n"; my $fd = $smb->open(">>smb://jupiter/doc/test", 0666) || print "Can't append to file:", $!, "\n";
- read($fd,$count)
-
Read $count bytes of data on file descriptor $fd. Return buffer read on success, undef at end of file, -1 is return on error and $! is set.
- write($fd,$buf)
-
Write $buf on file descriptor $fd. Return number of bytes wrote, else -1 is return and errno and $! is set.
Example:
my $fd = $smb->open(">smb://jupiter/doc/test", 0666) || print "Can't create file:", $!, "\n"; $smb->write($fd,"A test of write call", length("A test of write call")) || print $!,"\n"; $smb->close($fd);
- close($fd)
-
Close file descriptior $fd. Return 0 on success, else -1 is return and errno and $! is set.
Print method
- unlink_print_job($purl, $id)
-
Remove job number $id on printer $purl
- print_file($purl, $printer)
-
Print file $purl on $printer
TODO
chown
chmod
open_print_job
telldir
lseekdir
lseek
AUTHOR
Alain BARBET, alian@alianwebserver.com