I am trying to get a json file in a SFTP server from a Symfony2 command. I use KnpGaufretteBundle and the phpseclib-sftp adapter.
I have on my computer a running SFTP server, I can connect it with filezilla and list/read files so I do not think there is a permission issue.
The problem is the connection work, I can list the files with
$sftpService->getExec()->run("ls")
But I can't with
$sftpService->getSftp()->listDirectory(".")
I can create a directory but not list it.. and I can't read the files. Here is my test code:
$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
And the permissions of the base folder:
-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
Here is the warning for the read
function
Edit: I can read the file with $sftpService->getExec()->run("cat test.txt"));
Ok so it's seems like for SFTP urls (ssh2.STFP://...) I need to use the absolute path, the base folder of my ftp user does not work, so it's working with:
$sftp->read($sftp->realpath("test.txt"))