0

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?

2 Answers 2

2

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');
1
  • Sorry to hop onto such and old answer, I'm using the class you linked and am connecting to my share, however when I use file_get_contents for a file I'm getting the error url_stat(): dir failed for path. Any ideas? Commented Feb 17, 2017 at 20:28
0

Reviving old thread but I think I found the solution, the code must have changed since the pot was made on the blog:

print join ("\n", $smbc->get_last_stdout());

should now be

print join ("\n", $smbc->get_last_cmd_stdout());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.