PHP wrapper for smbclient
  • PHP 98.3%
  • Shell 1.3%
  • Nix 0.3%
  • Makefile 0.1%
Find a file
Robin Appelman dd983282a6 add badges
2014-07-22 02:12:55 +02:00
src remove unneeded destructor 2014-07-22 02:03:51 +02:00
tests skip username test 2014-07-22 02:07:29 +02:00
.gitignore Move to PSR-4 for autoloading 2014-04-07 13:54:49 +02:00
.travis.yml re-enable other php version 2014-07-22 02:08:58 +02:00
composer.json add coverage 2014-07-22 01:42:09 +02:00
COPYING-AGPL initial commit 2012-12-10 00:20:33 +01:00
COPYING-README initial commit 2012-12-10 00:20:33 +01:00
README.md add badges 2014-07-22 02:12:55 +02:00

SMB

Coverage Status Build Status

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
  • Support for using libsmbclient directly trough libsmbclient-php

Examples

Upload a file

<?php
use Icewind\SMB\Server;

require('vendor/autoload.php');

$fileToUpload = __FILE__;

$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$share->put($fileToUpload, 'example.txt');

Download a file

<?php
use Icewind\SMB\Server;

require('vendor/autoload.php');

$target = __DIR__ . '/target.txt';

$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$share->get('example.txt', $target);

List shares on the remote server

<?php
use Icewind\SMB\Server;

require('vendor/autoload.php');

$server = new Server('localhost', 'test', 'test');
$shares = $server->listShares();

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

List the content of a folder

<?php
use Icewind\SMB\Server;

require('vendor/autoload.php');

$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$content = $share->dir('test');

foreach ($content as $name => $info) {
	echo $name . "\n";
	echo "\tsize :" . $info['size'] . "\n";
}

Using libsmbclient-php

Install libsmbclient-php

<?php
use Icewind\SMB\Server;
use Icewind\SMB\NativeServer;

require('vendor/autoload.php');

$fileToUpload = __FILE__;

if (Server::NativeAvailable()) {
    $server = new NativeServer('localhost', 'test', 'test');
} else {
    echo 'libsmbclient-php not available, falling back to wrapping smbclient';
    $server = new Server('localhost', 'test', 'test');
}
$share = $server->getShare('test');
$share->put($fileToUpload, 'example.txt');