Search code examples
phpsamba

samba web client - setup connection in php script


I have to establish connection with Samba server from my php script in order to download some files into my local server.

Actually its first time I have heard of something like Samba so I Tried to look for a opensource code that I could make use of.

Here it is what I have found: First class - smbclient.php and I tried code posted on the page:

<?php

require_once ('smbclient.php');

$smbc = new smbclient ('//10.0.1.1/example', 'exampleuser', 'examplepassword');

if (!$smbc->get ('path/to/desired/file.txt', '/tmp/localfile.txt'))
{
    print "Failed to retrieve file:\n";
    print join ("\n", $smbc->get_last_stdout());
}
else
{
    print "Transferred file successfully.";
}

?>

Adjusting it into my needs ( server, user, password), all i got is

Failed to retrieve file: 
Fatal error: Call to undefined method smbclient::get_last_stdout() 

Then I found out about smbwebclient.php project which looks awesome and can be found here.

And this class looks good but the problem is that I have no idea how to use it. Can anyone post it example connection or link to tutorial?


Solution

  • To get files from a samba server, you can try to use a smb wrapper, like the one here but changing the deprecated splits with explodes. Then you can include your php file using this code:

    include_once('smb.php');
    include( 'smb://user:password@server/folder/file.php');