Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
webdav_client Class Reference

A Moodle-modified WebDAV client, based on webdav_client v0.1.5, a php based webdav client class. More...

Public Member Functions

 __construct ($server='', $user='', $pass='', $auth=false, $socket='', $oauthtoken='')
 #-
 
 __set ($key, $value)
 
 check_webdav ()
 Check's if server is a webdav compliant server.
 
 close ()
 Closes an open socket.
 
 copy_coll ($src_path, $dst_path, $overwrite)
 Public method copy_coll.
 
 copy_file ($src_path, $dst_path, $overwrite)
 Public method copy_file.
 
 delete ($path)
 Public method delete.
 
 get ($path, &$buffer, $fp=null)
 Public method get.
 
 get_file ($srcpath, $localpath)
 Public method get_file.
 
 gpi ($path)
 Public method gpi.
 
 is_dir ($path)
 Public method is_dir.
 
 is_file ($path)
 Public method is_file.
 
 lock ($path)
 Public method lock.
 
 ls ($path)
 Public method ls.
 
 mget ($filelist)
 Public method mget.
 
 mkcol ($path)
 Public method mkcol.
 
 move ($src_path, $dst_path, $overwrite)
 Public method move.
 
 mput ($filelist)
 Public method mput.
 
 open ()
 Open's a socket to a webdav server.
 
 options ()
 Get options from webdav server.
 
 put ($path, $data)
 Public method put.
 
 put_file ($path, $filename)
 Public method put_file.
 
 set_protocol ($version)
 Set which HTTP protocol will be used.
 
 unlock ($path, $locktoken)
 Public method unlock.
 

Detailed Description

A Moodle-modified WebDAV client, based on webdav_client v0.1.5, a php based webdav client class.

class webdav client. a php based nearly RFC 2518 conforming client.

This class implements methods to get access to an webdav server. Most of the methods are returning boolean false on error, an integer status (http response status) on success or an array in case of a multistatus response (207) from the webdav server. Look at the code which keys are used in arrays. It's your responsibility to handle the webdav server responses in an proper manner. Please notice that all Filenames coming from or going to the webdav server should be UTF-8 encoded (see RFC 2518). This class tries to convert all you filenames into utf-8 when it's needed.

Moodle modifications:

  • Moodle 3.4: Add support for OAuth 2 bearer token-based authentication
Author
Christian Juerges chris.nosp@m.tian.nosp@m..juer.nosp@m.ges@.nosp@m.xwave.nosp@m..ch, Xwave GmbH, Josefstr. 92, 8005 Zuerich - Switzerland
License
http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License

Constructor & Destructor Documentation

◆ __construct()

webdav_client::__construct ( $server = '',
$user = '',
$pass = '',
$auth = false,
$socket = '',
$oauthtoken = '' )

#-

Constructor - Initialise class variables

Parameters
string$serverHostname of the server to connect to
string$userUsername (for basic/digest auth, see $auth)
string$passPassword (for basic/digest auth, see $auth)
bool$authAuthentication type; one of ['basic', 'digest', 'bearer']
string$socketUsed protocol for fsockopen, usually: '' (empty) or 'ssl://'
string$oauthtokenOAuth 2 bearer token (for bearer auth, see $auth)

Member Function Documentation

◆ check_webdav()

webdav_client::check_webdav ( )

Check's if server is a webdav compliant server.

True if server returns a DAV Element in Header and when schema 1,2 is supported.

Return values
booltrue if server is webdav server. Otherwise false.

◆ copy_coll()

webdav_client::copy_coll ( $src_path,
$dst_path,
$overwrite )

Public method copy_coll.

Copies a collection on a webdav server

Duplicates a collection on the webdav server (serverside). All work is done on the webdav server. If you set param overwrite as true, the target will be overwritten.

Parameters
stringsrc_path, string dest_path, bool overwrite
Return values
intstatus code (look at rfc 2518). false on error.

◆ copy_file()

webdav_client::copy_file ( $src_path,
$dst_path,
$overwrite )

Public method copy_file.

Copies a file on a webdav server

Duplicates a file on the webdav server (serverside). All work is done on the webdav server. If you set param overwrite as true, the target will be overwritten.

Parameters
stringsrc_path, string dest_path, bool overwrite
Return values
intstatus code (look at rfc 2518). false on error.

◆ delete()

webdav_client::delete ( $path)

Public method delete.

deletes a collection/directory on a webdav server

Parameters
stringpath
Return values
intstatus code (look at rfc 2518). false on error.

◆ get()

webdav_client::get ( $path,
& $buffer,
$fp = null )

Public method get.

Gets a file from a webdav collection.

Parameters
string$paththe path to the file on the webdav server
string&$bufferthe buffer to store the data in
resource$fpoptional if included, the data is written directly to this resource and not to the buffer
Return values
string|boolstatus code and &$buffer (by reference) with response data from server on success. False on error.

◆ get_file()

webdav_client::get_file ( $srcpath,
$localpath )

Public method get_file.

Gets a file from a collection into local filesystem.

fopen() is used.

Parameters
string$srcpath
string$localpath
Return values
booltrue on success. false on error.

◆ gpi()

webdav_client::gpi ( $path)

Public method gpi.

Get's path information from webdav server for one element.

Parameters
stringpath
Return values
arraydirinfo. false on error

◆ is_dir()

webdav_client::is_dir ( $path)

Public method is_dir.

Gather whether a path points to a directory

Parameters
stringpath return bool true or false

◆ is_file()

webdav_client::is_file ( $path)

Public method is_file.

Gathers whether a path points to a file or not.

Parameters
stringpath
Return values
booltrue or false

◆ lock()

webdav_client::lock ( $path)

Public method lock.

Locks a file or collection.

Lock uses this->_user as lock owner.

Parameters
stringpath
Return values
intstatus code (look at rfc 2518). false on error.

◆ ls()

webdav_client::ls ( $path)

Public method ls.

Get's directory information from webdav server into flat a array using PROPFIND

All filenames are UTF-8 encoded. Have a look at _propfind_startElement what keys are used in array returned.

Parameters
stringpath
Return values
arraydirinfo, false on error

◆ mget()

webdav_client::mget ( $filelist)

Public method mget.

Gets multiple files and directories.

FileList must be in format array("remotepath" => "localpath"). Filenames are UTF-8 encoded.

Parameters
arrayfilelist
Return values
booltrue on succes, other int status code on error

◆ mkcol()

webdav_client::mkcol ( $path)

Public method mkcol.

Creates a new collection/directory on a webdav server

Parameters
stringpath
Return values
intstatus code received as response from webdav server (see rfc 2518)

◆ move()

webdav_client::move ( $src_path,
$dst_path,
$overwrite )

Public method move.

Moves a file or collection on webdav server (serverside)

If you set param overwrite as true, the target will be overwritten.

Parameters
stringsrc_path, string dest_path, bool overwrite
Return values
intstatus code (look at rfc 2518). false on error.

◆ mput()

webdav_client::mput ( $filelist)

Public method mput.

Puts multiple files and/or directories onto a webdav server.

Filenames should be allready UTF-8 encoded. Param fileList must be in format array("localpath" => "destpath").

Parameters
arrayfilelist
Return values
booltrue on success. otherwise int status code on error

◆ open()

webdav_client::open ( )

Open's a socket to a webdav server.

Return values
booltrue on success. Otherwise false.

◆ options()

webdav_client::options ( )

Get options from webdav server.

Return values
arraywith all header fields returned from webdav server. false if server does not speak http.

◆ put()

webdav_client::put ( $path,
$data )

Public method put.

Puts a file into a collection. Data is putted as one chunk!

Parameters
stringpath, string data
Return values
intstatus-code read from webdavserver. False on error.

◆ put_file()

webdav_client::put_file ( $path,
$filename )

Public method put_file.

Read a file as stream and puts it chunk by chunk into webdav server collection.

Look at php documenation for legal filenames with fopen(); The filename will be translated into utf-8 if not allready in utf-8.

Parameters
stringtargetpath, string filename
Return values
intstatus code. False on error.

◆ set_protocol()

webdav_client::set_protocol ( $version)

Set which HTTP protocol will be used.

Value 1 defines that HTTP/1.1 should be used (Keeps Connection to webdav server alive). Otherwise HTTP/1.0 will be used.

Parameters
intversion

◆ unlock()

webdav_client::unlock ( $path,
$locktoken )

Public method unlock.

Unlocks a file or collection.

Parameters
stringpath, string locktoken
Return values
intstatus code (look at rfc 2518). false on error.

The documentation for this class was generated from the following file: