I want to manage files on Nextcloud implementation (cd.wedos.com). I can connect to the server using WinSCP and list, download & upload files. I want to do the same via PHP. Thanks to SO I am able to connect to WebDAV server from my Windows 11 – my dev environment.
I did search on how to use Sabre WebDAV client, but no matter I do I have no idea how to list files.
$folder_content = $client->propfind('', []);
returns
array(5) {
["{DAV:}getlastmodified"]=>
string(29) "Thu, 18 Jul 2024 20:04:28 GMT"
["{DAV:}resourcetype"]=>
object(Sabre\DAV\Xml\Property\ResourceType)#14 (1) {
["value":protected]=>
array(1) {
[0]=>
string(16) "{DAV:}collection"
}
}
["{DAV:}quota-used-bytes"]=>
string(11) "11825361054"
["{DAV:}quota-available-bytes"]=>
string(13) "3286709522274"
["{DAV:}getetag"]=>
string(15) ""6699754ce26f9""
}
The official Sabre doc is using $client->propfind('collection', array(
but the parameter collection gives me error Not found, I used ''
instead
$client->propfind('', array(
'{DAV:}displayname',
'{DAV:}getcontentlength',
));
That returns
array(1) {
["{DAV:}displayname"]=>
string(47) "wedos-auth-modified-0f5f-4c87-99a2-modified"
}
Which I have no idea what it means.
I found other examples how to use propfind
$folder_content = $client->propfind('', array(
'{DAV:}getlastmodified',
'{DAV:}getcontenttype',
));
That gives me result
array(1) {
["{DAV:}getlastmodified"]=>
string(29) "Thu, 18 Jul 2024 20:04:28 GMT"
}
In the official documentation there is section called "Discovering WebDAV features". I thought it would help. So I ran it
$features = $client->options();
which returns something that does not help me.
array(8) {
[0]=>
string(1) "1"
[1]=>
string(1) "3"
[2]=>
string(14) "extended-mkcol"
[3]=>
string(14) "access-control"
[4]=>
string(40) "calendarserver-principal-property-search"
[5]=>
string(25) "nextcloud-checksum-update"
[6]=>
string(18) "nc-calendar-search"
[7]=>
string(27) "nc-enable-birthday-calendar"
}
Is there someone who can help me to list all files and directories of a particular folder?
Thanks to Olivier I was able to list using
curl.exe https://cd.wedos.com/remote.php/dav/files/wedos-auth-anonymized/upload --user username:password --request PROPFIND
It is not exactly listing directory via Sabre WebDAV client but I guess it will work... I hope I can use cURL for uploading and downloading files too.
I still prefer to use sabre client though
Pass 1
to the depth
(3rd) argument of the propfind
:
$folder_content = $client->propfind('', [], 1);
WebDAV protocol recognizes three depth levels:
PROPFIND
that means that only properties of the folder/file are returned