PHP wrapper for smbclient
  • PHP 98.3%
  • Shell 1.3%
  • Nix 0.3%
  • Makefile 0.1%
Find a file
2018-03-29 17:20:08 +02:00
src make workgroup explicit 2018-03-29 17:20:08 +02:00
tests make workgroup explicit 2018-03-29 17:20:08 +02:00
.gitignore add example file 2015-03-13 13:17:14 +01:00
.scrutinizer.yml get code coverage from both backends 2016-08-27 00:09:35 +02:00
.travis.yml clean travis config a bit 2018-03-27 16:57:13 +02:00
composer.json move backends into their own namespace and add support for multiple auth methods 2018-03-13 19:05:41 +01:00
example.php make workgroup explicit 2018-03-29 17:20:08 +02:00
install_libsmbclient.sh run travis on ubuntu 14.04 2016-12-08 16:05:32 +01:00
LICENSE.txt add license file 2014-11-27 18:38:59 +01:00
Makefile clean travis config a bit 2018-03-27 16:57:13 +02:00
README.md make workgroup explicit 2018-03-29 17:20:08 +02:00

SMB

Code Coverage Build Status Scrutinizer Code Quality

PHP wrapper for smbclient and libsmbclient-php

  • Reuses a single smbclient instance for multiple requests
  • Doesn't leak the password to the process list
  • Simple 1-on-1 mapping of SMB commands
  • A stream-based api to remove the need for temporary files
  • Support for using libsmbclient directly trough libsmbclient-php

Examples

Connect to a share

<?php
use Icewind\SMB\ServerFactory;
use Icewind\SMB\BasicAuth;

require('vendor/autoload.php');

$serverFactory = new ServerFactory();
$auth = new BasicAuth('test', 'workgroup', 'test');
$server = $serverFactory->createServer('localhost', $auth);

$share = $server->getShare('test');

The server factory will automatically pick between the smbclient and libsmbclient-php based backend depending on what is available.

Using anonymous authentication

$serverFactory = new ServerFactory();
$auth = new AnonymousAuth();
$server = $serverFactory->createServer('localhost', $auth);

Using kerberos authentication

$serverFactory = new ServerFactory();
$auth = new KerberosAuth();
$server = $serverFactory->createServer('localhost', $auth);

Note that this requires a valid kerberos ticket to already be available for php

Upload a file

$share->put($fileToUpload, 'example.txt');

Download a file

$share->get('example.txt', $target);

List shares on the remote server

$shares = $server->listShares();

foreach ($shares as $share) {
	echo $share->getName() . "\n";
}

List the content of a folder

$content = $share->dir('test');

foreach ($content as $info) {
	echo $info->getName() . "\n";
	echo "\tsize :" . $info->getSize() . "\n";
}

Using read streams

$fh = $share->read('test.txt');
echo fread($fh, 4086);
fclose($fh);

Using write streams

$fh = $share->write('test.txt');
fwrite($fh, 'bar');
fclose($fh);

Using notify

$share->notify('')->listen(function (\Icewind\SMB\Change $change) {
	echo $change->getCode() . ': ' . $change->getPath() . "\n";
});

Testing SMB

Use the following steps to check if the library can connect to your SMB share.

  1. Clone this repository or download the source as zip
  2. Make sure composer is installed
  3. Run composer install in the root of the repository
  4. Edit example.php with the relevant settings for your share.
  5. Run php example.php

If everything works correctly then the contents of the share should be outputted.