如何用PHP WebDAV客户端(Sabre)列出Nextcloud文件目录?
如何用PHP(Sabre WebDAV客户端)列出Wedos上Nextcloud实例的文件目录?
我需要管理Wedos(cd.wedos.com)上的Nextcloud实例文件,目前能通过WinSCP连接服务器完成文件的列出、下载和上传操作,希望用PHP实现同样功能。已在Windows 11开发环境中成功连接到WebDAV服务器,但用Sabre WebDAV客户端始终无法实现文件列出。
尝试执行以下代码:
$folder_content = $client->propfind('', []);
返回结果:
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\"" }
Sabre官方文档示例使用$client->propfind('collection', array(,但传入collection参数会提示“Not found”错误,改用空字符串后执行:
$client->propfind('', array( '{DAV:}displayname', '{DAV:}getcontentlength', ));
返回结果:
array(1) { ["{DAV:}displayname"]=> string(47) "wedos-auth-modified-0f5f-4c87-99a2-modified" }
无法理解该结果的含义。
尝试其他propfind示例:
$folder_content = $client->propfind('', array( '{DAV:}getlastmodified', '{DAV:}getcontenttype', ));
返回结果:
array(1) { ["{DAV:}getlastmodified"]=> string(29) "Thu, 18 Jul 2024 20:04:28 GMT" }
还尝试了官方文档“Discovering WebDAV features”部分的代码:
$features = $client->options();
返回结果:
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" }
该结果没有实际帮助,希望有人能帮忙实现列出指定文件夹下的所有文件和目录。
感谢Olivier的帮助,已通过以下curl命令实现列出功能:
curl.exe https://cd.wedos.com/remote.php/dav/files/wedos-auth-anonymized/upload --user username:password --request PROPFIND
这并非通过Sabre WebDAV客户端实现,但暂时可用。也希望能用curl完成上传和下载操作,但仍偏好使用Sabre客户端。
内容的提问来源于stack exchange,提问作者Radek
相关产品推荐
相关产品推荐

