2013-05-27 42 views
0

我必須建立與我的php腳本中的Samba服務器的連接,才能將一些文件下載到本地服務器。samba web客戶端 - 在php腳本中建立連接

其實它第一次聽說Samba之類的東西,所以我試圖尋找一個我可以利用的開源代碼。

這是我發現:First class - smbclient.php,我試圖張貼在網頁代碼:

<?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."; 
} 

?> 

它調整到我的需要(服務器,用戶名,密碼),我的一切是

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

然後我找到了約smbwebclient.php項目,看起來很棒,可以找到here

這個類看起來不錯,但問題是我不知道如何使用它。任何人都可以發佈示例連接或鏈接到教程?

回答

1

要從samba服務器獲取文件,您可以嘗試使用smb包裝,如here,但更改帶有爆炸的棄用拆分。然後,你可以使用此代碼包含你的PHP文件:

include_once('smb.php'); 
include('smb://user:[email protected]/folder/file.php'); 
+0

對不起,跳上這樣老的回答,我用你鏈接的類和我連接到我的共享,但是當我使用的file_get_contents一個文件,我得到的錯誤'url_stat( ):dir失敗了r路徑'。有任何想法嗎? –

0

振興老線程,但我想我找到了解決方案,該代碼必須改變,因爲鍋的博客上發了言:

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

現在應該

print join ("\n", $smbc->get_last_cmd_stdout()); 
相關問題