SmbClient(3pm) | User Contributed Perl Documentation | SmbClient(3pm) |
Filesys::SmbClient - Interface for access Samba filesystem with libsmclient.so
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); # ...
See section EXAMPLE for others scripts.
Provide interface to access routine defined in libsmbclient.so provided with Samba.
Since 3.0 release of this package, you need a least samba-3.0.2. For prior release of Samba, use Filesys::SmbClient version 1.x.
For old and 2.x release, this library is available on Samba source, but is not build by default. Do "make bin/libsmbclient.so" in sources directory of Samba to build this libraries. Then copy source/include/libsmbclient.h to /usr/local/samba/include and source/bin/libsmbclient.so to /usr/local/samba/lib before install this module.
If you want to use filehandle with this module, you need Perl 5.6 or later.
When a path is used, his scheme is :
smb://server/share/rep/doc
$Revision: 3.2 $
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);
This didn't work before 5.005_64. Why, I don't know. When you have tied a filehandle with Filesys::SmbClient, you can call classic methods for filehandle: print, printf, seek, syswrite, getc, open, close, read. See perldoc for usage.
Example:
local *FD; tie(*FD, 'Filesys::SmbClient'); open(FD,"smb://jupiter/doc/test") or print "Can't open file:", $!, "\n"; while(<FD>) { print $_; } close(FD);
or
local *FD; tie(*FD, 'Filesys::SmbClient'); open(FD,">smb://jupiter/doc/test") or print "Can't create file:", $!, "\n"; print FD "Samba test","\n"; printf FD "%s", "And that work !\n"; close(FD);
Example:
$smb->mkdir("smb://jupiter/doc/toto",'0666') or print "Error mkdir: ", $!, "\n";
Example:
$smb->rmdir("smb://jupiter/doc/toto") or print "Error rmdir: ", $!, "\n";
Example:
$smb->rmdir_recurse("smb://jupiter/doc/toto") or print "Error rmdir_recurse: ", $!, "\n";
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);
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);
List is made with:
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); }
Example:
$smb->rename("smb://jupiter/doc/toto","smb://jupiter/doc/tata") or print "Can't rename file:", $!, "\n";
Example:
$smb->unlink("smb://jupiter/doc/test") or print "Can't unlink file:", $!, "\n";
Example:
my $fd = $smb->open("smb://jupiter/doc/test", 0666) or print "Can't read file:", $!, "\n"; my $fd = $smb->open(">smb://jupiter/doc/test", 0666) or print "Can't create file:", $!, "\n"; my $fd = $smb->open(">>smb://jupiter/doc/test", 0666) or print "Can't append to file:", $!, "\n";
Return buffer read on success, undef at end of file, -1 is return on error and $! is set.
FILEHANDLE must be open with open of this module.
Example:
my $fd = $smb->open(">smb://jupiter/doc/test", 0666) or print "Can't create file:", $!, "\n"; $smb->write($fd, "A test of write call") or print $!,"\n"; $smb->close($fd);
FILEHANDLE must be open with open of this module.
FILEHANDLE must be open with open of this module.
Close open files, release Samba connection, delete context, acquired during open_* calls.
Example:
$smb->shutdown(0); # Gracefully close connection $sbm->shutdown(1); # Forcibly close files and connection
NOTE:
shutdown(1) may cause complaints about talloc memory
leaks, if there are currently no open files.
This module come with some scripts:
The Filesys-SmbClient module is Copyright (c) 1999-2003 Alain BARBET, France, alian at cpan.org. All rights reserved.
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
2022-10-19 | perl v5.36.0 |