1SmbClient(3) User Contributed Perl Documentation SmbClient(3)
2
3
4
6 Filesys::SmbClient - Interface for access Samba filesystem with
7 libsmclient.so
8
10 use POSIX;
11 use Filesys::SmbClient;
12
13 my $smb = new Filesys::SmbClient(username => "alian",
14 password => "speed",
15 workgroup => "alian",
16 debug => 10);
17
18 # Read a file
19 my $fd = $smb->open("smb://jupiter/doc/general.css", '0666');
20 while (defined(my $l= $smb->read($fd,50))) {print $l; }
21 $smb->close(fd);
22
23 # ...
24
25 See section EXAMPLE for others scripts.
26
28 Provide interface to access routine defined in libsmbclient.so provided
29 with Samba.
30
31 Since 3.0 release of this package, you need a least samba-3.0.2. For
32 prior release of Samba, use Filesys::SmbClient version 1.x.
33
34 For old and 2.x release, this library is available on Samba source, but
35 is not build by default. Do "make bin/libsmbclient.so" in sources
36 directory of Samba to build this libraries. Then copy
37 source/include/libsmbclient.h to /usr/local/samba/include and
38 source/bin/libsmbclient.so to /usr/local/samba/lib before install this
39 module.
40
41 If you want to use filehandle with this module, you need Perl 5.6 or
42 later.
43
44 When a path is used, his scheme is :
45
46 smb://server/share/rep/doc
47
49 $Revision: 3.2 $
50
52 new %hash
53 Init connection Hash can have this keys:
54
55 · username
56
57 · password
58
59 · workgroup
60
61 · debug
62
63 · flags : See set_flag
64
65 Return instance of Filesys::SmbClient on succes, die with error
66 else.
67
68 Example:
69
70 my $smb = new Filesys::SmbClient(username => "alian",
71 password => "speed",
72 workgroup => "alian",
73 debug => 10);
74
75 set_flag
76 Set flag for smb connection. See _SMBCCTX->flags in libsmclient.h
77 Flag can be:
78
79 SMB_CTX_FLAG_USE_KERBEROS
80 SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS
81 SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON
82
83 Tie Filesys::SmbClient filehandle
84 This didn't work before 5.005_64. Why, I don't know. When you have
85 tied a filehandle with Filesys::SmbClient, you can call classic methods
86 for filehandle: print, printf, seek, syswrite, getc, open, close, read.
87 See perldoc for usage.
88
89 Example:
90
91 local *FD;
92 tie(*FD, 'Filesys::SmbClient');
93 open(FD,"smb://jupiter/doc/test")
94 or print "Can't open file:", $!, "\n";
95 while(<FD>) { print $_; }
96 close(FD);
97
98 or
99
100 local *FD;
101 tie(*FD, 'Filesys::SmbClient');
102 open(FD,">smb://jupiter/doc/test")
103 or print "Can't create file:", $!, "\n";
104 print FD "Samba test","\n";
105 printf FD "%s", "And that work !\n";
106 close(FD);
107
108 Directory
109 mkdir FILENAME, MODE
110 Create directory $fname with permissions set to $mode. Return 1 on
111 success, else 0 is return and errno and $! is set.
112
113 Example:
114
115 $smb->mkdir("smb://jupiter/doc/toto",'0666')
116 or print "Error mkdir: ", $!, "\n";
117
118 rmdir FILENAME
119 Erase directory $fname. Return 1 on success, else 0 is return and
120 errno and $! is set. ($fname must be empty, else see
121 rmdir_recurse).
122
123 Example:
124
125 $smb->rmdir("smb://jupiter/doc/toto")
126 or print "Error rmdir: ", $!, "\n";
127
128 rmdir_recurse FILENAME
129 Erase directory $fname. Return 1 on success, else 0 is return and
130 errno and $! is set. Il $fname is not empty, all files and dir will
131 be deleted.
132
133 Example:
134
135 $smb->rmdir_recurse("smb://jupiter/doc/toto")
136 or print "Error rmdir_recurse: ", $!, "\n";
137
138 opendir FILENAME
139 Open directory $fname. Return file descriptor on succes, else 0 is
140 return and $! is set.
141
142 readdir FILEHANDLE
143 Read a directory. In a list context, return the full content of the
144 directory $fd, else return next element. Each elem is a name of a
145 directory or files.
146
147 Return undef at end of directory.
148
149 Example:
150
151 my $fd = $smb->opendir("smb://jupiter/doc");
152 foreach my $n ($smb->readdir($fd)) {print $n,"\n";}
153 close($fd);
154
155 readdir_struct FILEHANDLE
156 Read a directory. In a list context, return the full content of the
157 directory FILEHANDLE, else return next element. Each element is a
158 ref to an array with type, name and comment. Type can be :
159
160 SMBC_WORKGROUP
161 SMBC_SERVER
162 SMBC_FILE_SHARE
163 SMBC_PRINTER_SHARE
164 SMBC_COMMS_SHARE
165 SMBC_IPC_SHARE
166 SMBC_DIR
167 SMBC_FILE
168 SMBC_LINK
169
170 Return undef at end of directory.
171
172 Example:
173
174 my $fd = $smb->opendir("smb://jupiter/doc");
175 while (my $f = $smb->readdir_struct($fd)) {
176 if ($f->[0] == SMBC_DIR) {print "Directory ",$f->[1],"\n";}
177 elsif ($f->[0] == SMBC_FILE) {print "File ",$f->[1],"\n";}
178 # ...
179 }
180 close($fd);
181
182 closedir FILEHANDLE
183 Close directory $fd.
184
185 Files
186 stat FILENAME
187 Stat a file FILENAME. Return a list with info on success, else an
188 empty list is return and $! is set.
189
190 List is made with:
191
192 · device
193
194 · inode
195
196 · protection
197
198 · number of hard links
199
200 · user ID of owner
201
202 · group ID of owner
203
204 · device type (if inode device)
205
206 · total size, in bytes
207
208 · blocksize for filesystem I/O
209
210 · number of blocks allocated
211
212 · time of last access
213
214 · time of last modification
215
216 · time of last change
217
218 Example:
219
220 my @tab = $smb->stat("smb://jupiter/doc/tata");
221 if ($#tab == 0) { print "Erreur in stat:", $!, "\n"; }
222 else {
223 for (10..12) {$tab[$_] = localtime($tab[$_]);}
224 print join("\n",@tab);
225 }
226
227 fstat FILEHANDLE
228 Like stat, but on a file handle
229
230 rename OLDNAME,NEWNAME
231 Changes the name of a file; an existing file NEWNAME will be
232 clobbered. Returns true for success, false otherwise, with $! set.
233
234 Example:
235
236 $smb->rename("smb://jupiter/doc/toto","smb://jupiter/doc/tata")
237 or print "Can't rename file:", $!, "\n";
238
239 unlink FILENAME
240 Unlink FILENAME. Return 1 on success, else 0 is return and errno
241 and $! is set.
242
243 Example:
244
245 $smb->unlink("smb://jupiter/doc/test")
246 or print "Can't unlink file:", $!, "\n";
247
248 open FILENAME
249 open FILENAME, MODE
250 Open file $fname with perm $mode. Return file descriptor on
251 success, else 0 is return and $! is set.
252
253 Example:
254
255 my $fd = $smb->open("smb://jupiter/doc/test", 0666)
256 or print "Can't read file:", $!, "\n";
257
258 my $fd = $smb->open(">smb://jupiter/doc/test", 0666)
259 or print "Can't create file:", $!, "\n";
260
261 my $fd = $smb->open(">>smb://jupiter/doc/test", 0666)
262 or print "Can't append to file:", $!, "\n";
263
264 read FILEHANDLE
265 read FILEHANDLE, LENGTH
266 Read $count bytes of data on file descriptor $fd. It lenght is not
267 set, 4096 bytes will be read.
268
269 Return buffer read on success, undef at end of file, -1 is return
270 on error and $! is set.
271
272 FILEHANDLE must be open with open of this module.
273
274 write FILEHANDLE, $buf
275 write FILEHANDLE, @buf
276 Write $buf or @buf on file descriptor $fd. Return number of bytes
277 wrote, else -1 is return and errno and $! is set.
278
279 Example:
280
281 my $fd = $smb->open(">smb://jupiter/doc/test", 0666)
282 or print "Can't create file:", $!, "\n";
283 $smb->write($fd, "A test of write call")
284 or print $!,"\n";
285 $smb->close($fd);
286
287 FILEHANDLE must be open with open of this module.
288
289 seek FILEHANDLE, POS
290 Sets FILEHANDLE's position, just like the "fseek" call of "stdio".
291 FILEHANDLE may be an expression whose value gives the name of the
292 filehandle. The values for WHENCE is always SEEK_SET beacause
293 others didn't work on libsmbclient.so
294
295 FILEHANDLE must be open with open of this module.
296
297 close FILEHANDLE
298 Close file FILEHANDLE. Return 0 on success, else -1 is return and
299 errno and $! is set.
300
301 shutdown flag
302 A wrapper around `libsmbclient's `smbc_free_context'.
303
304 Close open files, release Samba connection, delete context, aquired
305 during open_* calls.
306
307 Example:
308
309 $smb->shutdown(0); # Gracefully close connection
310 $sbm->shutdown(1); # Forcibly close files and connection
311
312 NOTE:
313 shutdown(1) may cause complaints about talloc memory
314 leaks, if there are currently no open files.
315
316 Print method
317 unlink_print_job PRINTER_URL, IDJOB
318 Remove job number IDJOB on printer PRINTER_URL
319
320 print_file DOCUMENT_URL, PRINTER_URL
321 Print file DOCUMENT_URL on PRINTER_URL
322
324 · chown
325
326 · chmod
327
328 · open_print_job
329
330 · telldir
331
332 · lseekdir
333
335 This module come with some scripts:
336
337 t/*.t
338 Just for check that this module is ok :-)
339
340 smb2www-2.cgi
341 A CGI interface with these features:
342
343 · browse workgroup ,share, dir
344
345 · read file
346
347 · upload file
348
349 · create directory
350
351 · unlink file, directory
352
354 The Filesys-SmbClient module is Copyright (c) 1999-2003 Alain BARBET,
355 France, alian at cpan.org. All rights reserved.
356
357 You may distribute under the terms of either the GNU General Public
358 License or the Artistic License, as specified in the Perl README file.
359
361 Hey! The above document had some coding errors, which are explained
362 below:
363
364 Around line 807:
365 '=item' outside of any '=over'
366
367 Around line 823:
368 You forgot a '=back' before '=head2'
369
370
371
372perl v5.30.0 2019-07-26 SmbClient(3)