2016-10-06 28 views
1

我想從Symfony2命令獲取SFTP服務器中的json文件。我使用KnpGaufretteBundlephpseclib-sftp適配器。帶Gaufrette和Phpseclib的SFTP無法讀取文件

我在我的計算機上運行的SFTP服務器,我可以將它與filezilla連接並列出/讀取文件,所以我不認爲存在權限問題。

的問題是連接的工作,我可以列出文件與

$sftpService->getExec()->run("ls") 

但我不能與

$sftpService->getSftp()->listDirectory(".") 

我可以創建一個目錄,但沒有列出它..和我無法讀取文件。這裏是我的測試代碼:

$sftpService = $this->getContainer()->get("phpseclib_sftp"); 
dump($sftpService->getExec()->run("ls")); //file "test.txt" exist 
$sftp = $sftpService->getSftp(); 
dump($sftp->exists("test.txt")); //false 
dump($sftp->read("test.txt")); //false 
dump($sftp->mkdir("testMkdir")); //true 
dump($sftpService->getExec()->run("ls")); //the new directory exist 
dump($sftp->listDirectory("testMkdir")); //false 

,這裏是輸出: Console output

和基礎文件夾的權限:

-rwxrwxrwx 1 sftp_user staff 11 6 oct 10:31 test.txt 
drwxr-xr-x 2 sftp_user staff 68 6 oct 10:56 testMkdir 

下面是read功能警告 enter image description here我可以看$sftpService->getExec()->run("cat test.txt"));

回答

1

好了,所以它看起來像SFTP的URL(ssh2.STFP:// ...)我需要使用絕對路徑,我的FTP用戶的基本文件夾不能正常工作,所以它的工作有:

$sftp->read($sftp->realpath("test.txt"))