PHP code example of icewind / smb

1. Go to this page and download the library: Download icewind/smb library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

icewind / smb example snippets



use Icewind\SMB\ServerFactory;
use Icewind\SMB\BasicAuth;

er', 'workgroup', 'password');
$server = $serverFactory->createServer('localhost', $auth);

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

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

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

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

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

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

$shares = $server->listShares();

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

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

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

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

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

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

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

$options = new Options();
$options->setTimeout(5);
$serverFactory = new ServerFactory($options);

$options = new Options();
$options->setMinProtocol(IOptions::PROTOCOL_SMB2);
$options->setMaxProtocol(IOptions::PROTOCOL_SMB3);
$serverFactory = new ServerFactory($options);