public function __construct($params) { if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) { if (Server::NativeAvailable()) { $this->server = new NativeServer($params['host'], $params['user'], $params['password']); } else { $this->server = new Server($params['host'], $params['user'], $params['password']); } $this->share = $this->server->getShare(trim($params['share'], '/')); $this->root = isset($params['root']) ? $params['root'] : '/'; if (!$this->root || $this->root[0] != '/') { $this->root = '/' . $this->root; } if (substr($this->root, -1, 1) != '/') { $this->root .= '/'; } } else { throw new \Exception('Invalid configuration'); } }
/** * check if smbclient is installed */ public static function checkDependencies() { return (bool) \OC_Helper::findBinaryPath('smbclient') || Server::NativeAvailable() ? true : ['smbclient']; }
<?php use Icewind\SMB\NativeServer; use Icewind\SMB\Server; require 'vendor/autoload.php'; if (Server::NativeAvailable()) { $server = new NativeServer('localhost', 'test', 'test'); } else { $server = new Server('localhost', 'test', 'test'); } $share = $server->getShare('test'); $share->put(__FILE__, 'example.php'); $files = $share->dir('/'); foreach ($files as $file) { echo $file->getName() . "\n"; }