Class WebDAVClient
The WebDAVClient class supports the WebDAV methods GET, PUT, MKCOL, MOVE, COPY, PROPFIND,OPTIONS and DELETE.
Note: when this class is used with sensitive data, be careful in persisting sensitive information to disk. The client can be used as shown in the following example:
The WebDAV client supports the following authentication schemes:
- Basic authentication
- Digest authentication
The methods of this class do not generally throw exceptions if the underlying WebDAV operation do not succeed.The result of a WebDAV operation can be checked using the methods succeeded(), getStatusCode(), and getStatusText().
Important note: This WebDAV client cannot be used to access the Commerce Cloud Digital server via WebDAV protocol.
| Constant | Description |
|---|---|
| DEFAULT_ENCODING: String = "UTF-8" | The default encoding character set. |
| DEFAULT_GET_FILE_SIZE: Number = 5242880 | The default size for get() returning a File is 5MB. |
| DEFAULT_GET_STRING_SIZE: Number = 2097152 | The default size for get() returning a String is 2MB. |
| DEPTH_0: Number = 0 | The depth of searching a WebDAV destination using the PROPFIND method - if that depth is given to the PROPFIND method as an input parameter the destination will be searched only on the level of the given path and a list of all containing files on that level will be returned [is not supported by every server]. |
| DEPTH_1: Number = 1 | The depth of searching a WebDAV destination using the PROPFIND method - if that depth is given to the PROPFIND method as an input parameter the destination will be searched until one level under the given path and a list of all containing files in that two levels [/path and one level underneath] will be returned [is not supported by every server]. |
| DEPTH_INIFINITY: Number = 2147483647 | The depth of searching a WebDAV destination using the PROPFIND method - if that depth is given to the PROPFIND method as an input parameter the destination will be fully searched and a list of all containing files will be returned [is not supported by every server]. |
| MAX_GET_FILE_SIZE: Number = 209715200 | The maximum size for get() returning a File is forty times the default size for getting a file. |
| MAX_GET_STRING_SIZE: Number = 10485760 | The maximum size for get() returning a String is five times the default size for getting a String. |
| Property | Description |
|---|---|
allResponseHeaders: HashMap (read-only) | Returns a HashMap of all response headers. |
statusCode: Number (read-only) | Returns the status code after the execution of a method. |
statusText: String (read-only) | Returns the status text after the execution of a method. |
| Constructor | Description |
|---|---|
| WebDAVClient(String, String, String) | Creates a new client for the use at a server which requires authentication. |
| WebDAVClient(String) | Creates a new client for the use at a server which does not require authentication. |
| Method | Description |
|---|---|
| addRequestHeader(String, String) | Adds a request header to the next WebDAV call. |
| close() | Closes the current connection to the server. |
| copy(String, String) | Copies a file on the server from one place rootUrl/origin to the other rootUrl/destination. |
| copy(String, String, Boolean) | Copies a file on the server from one place rootUrl/origin to the other rootUrl/destination. |
| copy(String, String, Boolean, Boolean) | Copies a file on the server from one place rootUrl/origin to the other rootUrl/destination. |
| del(String) | Deletes a file or directory from the remote server that can be found under rootUrl/path. |
| get(String) | Reads the content of a remote file or directory that can be found under rootUrl/path and returns a string representation of the data found in the DEFAULT_ENCODING encoding. |
| get(String, File) | Reads the content of a remote file or directory that can be found under rootUrl/path in DEFAULT_ENCODING encoding and writes a File in the system's standard encoding, which is "UTF-8". |
| get(String, File, Number) | Reads the content of a remote file or directory that can be found under rootUrl/path in DEFAULT_ENCODING encoding and writes a File in the system's standard encoding, which is "UTF-8". |
| get(String, File, String, Number) | Reads the content of a remote file or directory that can be found under rootUrl/path in the passed encoding and writes a File in the system standard encoding, which is "UTF-8". |
| get(String, String) | Reads the content of a remote file or directory that can be found under rootUrl/path and returns a string representation of the data found in the given encoding. |
| get(String, String, Number) | Reads the content of a remote file or directory that can be found under rootUrl/path and returns a string representation of the data found in the given encoding. |
| getAllResponseHeaders() | Returns a HashMap of all response headers. |
| getBinary(String, File) | Reads the content of a remote binary file that can be found under rootUrl/path and creates a local copy in File. |
| getBinary(String, File, Number) | Reads the content of a remote binary file that can be found under rootUrl/path and creates a local copy in File. |
| getResponseHeader(String) | Returns a specified response header - multiple headers are separated by CRLF. |
| getStatusCode() | Returns the status code after the execution of a method. |
| getStatusText() | Returns the status text after the execution of a method. |
| mkcol(String) | Creates a directory on the remote server on the location rootUrl/path. |
| move(String, String) | Moves a file on the server from one place rootUrl + "/" +origin to the other rootUrl/destination. |
| move(String, String, Boolean) | Moves a file on the server from one place rootUrl/origin to the other rootUrl/destination Can also be used to rename a remote file. |
| options(String) | Returns a list of methods which can be executed on the server location rootUrl/path. |
| propfind(String) | Get file listing of a remote location. |
| propfind(String, Number) | Get file listing of a remote location. |
| put(String, File) | Puts content out of a passed local file into a remote located file at rootUrl/path. |
| put(String, String) | Puts content encoded with DEFAULT_ENCODING into a remote located file at rootUrl/path. |
| put(String, String, String) | Puts content encoded with the passed encoding into a remote located file at rootUrl/path. |
| succeeded() | Returns true if the last executed WebDAV method was executed successfully - otherwise false. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
- DEFAULT_ENCODING: String = "UTF-8"
The default encoding character set.
- DEFAULT_GET_FILE_SIZE: Number = 5242880
The default size for
get()returning a File is 5MB.
- DEFAULT_GET_STRING_SIZE: Number = 2097152
The default size for
get()returning a String is 2MB.
- DEPTH_0: Number = 0
The depth of searching a WebDAV destination using the PROPFIND method - if that depth is given to the PROPFIND method as an input parameter the destination will be searched only on the level of the given path and a list of all containing files on that level will be returned [is not supported by every server].
- DEPTH_1: Number = 1
The depth of searching a WebDAV destination using the PROPFIND method - if that depth is given to the PROPFIND method as an input parameter the destination will be searched until one level under the given path and a list of all containing files in that two levels [/path and one level underneath] will be returned [is not supported by every server].
- DEPTH_INIFINITY: Number = 2147483647
The depth of searching a WebDAV destination using the PROPFIND method - if that depth is given to the PROPFIND method as an input parameter the destination will be fully searched and a list of all containing files will be returned [is not supported by every server].
- MAX_GET_FILE_SIZE: Number = 209715200
The maximum size for
get()returning a File is forty times the default size for getting a file. The largest file allowed is 200MB.
- MAX_GET_STRING_SIZE: Number = 10485760
The maximum size for
get()returning a String is five times the default size for getting a String. The largest String allowed is 10MB.
- statusCode: Number
(read-only) Returns the status code after the execution of a method.
- statusText: String
(read-only) Returns the status text after the execution of a method.
- WebDAVClient(rootUrl: String, username: String, password: String)
Creates a new client for the use at a server which requires authentication. The client supports the following authentication schemes: - Basic authentication scheme - Digest authentication scheme
Parameters:
- rootUrl - the url of the server one wants to connect to. All commands will be executed by the client relative to that url.
- username - username of the user for server authentication.
- password - password of the user for server authentication.
- WebDAVClient(rootUrl: String)
Creates a new client for the use at a server which does not require authentication.
Parameters:
- rootUrl - the url of the server one wants to connect to. All commands will be executed by the client relative to that url.
- addRequestHeader(headerName: String, headerValue: String): void
Adds a request header to the next WebDAV call.
Parameters:
- headerName - name of the header.
- headerValue - value of the header.
- close(): void
Closes the current connection to the server.
- copy(origin: String, destination: String): Boolean
Copies a file on the server from one place
rootUrl/originto the otherrootUrl/destination. Ifdestinationalready exists it gets overwritten. Returns true if succeeded, otherwise false.Parameters:
- origin - The origin where a file is located, relative to the
rootUrlstated when instantiating the client. - destination - The destination where the file should be copied to, relative to the
rootUrlstated when instantiating the client.
Returns:
- true if succeeded, otherwise false.
- origin - The origin where a file is located, relative to the
- copy(origin: String, destination: String, overwrite: Boolean): Boolean
Copies a file on the server from one place
rootUrl/originto the otherrootUrl/destination. If the passed parameteroverwriteis true anddestinationalready exists it gets overwritten. Returns true if succeeded, otherwise false.Parameters:
- origin - The origin where a file is located, relative to the
rootUrlstated when instantiating the client. - destination - The destination where the file should be copied to, relative to the
rootUrlstated when instantiating the client. - overwrite - A flag which determines whether the destination gets overwritten if it exists before copying.
Returns:
- true if succeeded, otherwise false.
- origin - The origin where a file is located, relative to the
- copy(origin: String, destination: String, overwrite: Boolean, shallow: Boolean): Boolean
Copies a file on the server from one place
rootUrl/originto the otherrootUrl/destination. If the passed parameteroverwriteis true anddestinationalready exists it gets overwritten. If the passed parametershallowis true a flat copy mechanism is used.Returns true if succeeded, otherwise false.
Parameters:
- origin - The origin where a file is located, relative to the
rootUrlstated when instantiating the client. - destination - The destination where the file should be copied to, relative to the
rootUrlstated when instantiating the client. - overwrite - A flag which determines whether the destination gets overwritten if it exits before copying
- shallow - A flag which determines how to copy the given data.
Returns:
- true if succeeded, otherwise false.
- origin - The origin where a file is located, relative to the
- del(path: String): Boolean
Deletes a file or directory from the remote server that can be found under
rootUrl/path. Returns true if succeeded, otherwise false.Parameters:
- path - The path of the file or collection to delete, relative to the
rootUrlstated when instantiating the client.
Returns:
- true if succeeded, otherwise false.
- path - The path of the file or collection to delete, relative to the
- get(path: String): String
Reads the content of a remote file or directory that can be found under
rootUrl/pathand returns a string representation of the data found in the DEFAULT_ENCODING encoding. If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Returns at most DEFAULT_GET_STRING_SIZE bytes.Parameters:
- path - The path of the collection or file one wants to get, relative to the
rootUrlstated when instantiating the client.
Returns:
- returns the String representation of the data found on the given path.
- path - The path of the collection or file one wants to get, relative to the
- get(path: String, file: File): Boolean
Reads the content of a remote file or directory that can be found under
rootUrl/pathin DEFAULT_ENCODING encoding and writes a File in the system's standard encoding, which is "UTF-8". If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Receives at most DEFAULT_GET_FILE_SIZE bytes which determines the file size of the local file. Returns true if succeeded otherwise false.Parameters:
- path - The path of the collection or file one wants to get - relative to the
rootUrlstated when instantiating the client. - file - The file to save the received data in.
Returns:
- returns true if succeeded, otherwise false.
- path - The path of the collection or file one wants to get - relative to the
- get(path: String, file: File, maxFileSize: Number): Boolean
Reads the content of a remote file or directory that can be found under
rootUrl/pathin DEFAULT_ENCODING encoding and writes a File in the system's standard encoding, which is "UTF-8". If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Receives at most maxFileSize bytes which determines the file size of the local file. Returns true if succeeded, otherwise false.Parameters:
- path - The path of the collection or file one wants to get - relative to the
rootUrlstated when instantiating the client. - file - The file to save the received data in.
- maxFileSize - The maximum size of bytes to stream into the file. Not to exceed MAX_GET_FILE_SIZE.
Returns:
- returns true if succeeded, otherwise false.
- path - The path of the collection or file one wants to get - relative to the
- get(path: String, file: File, encoding: String, maxFileSize: Number): Boolean
Reads the content of a remote file or directory that can be found under
rootUrl/pathin the passed encoding and writes a File in the system standard encoding, which is "UTF-8". If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Receives at most maxFileSize bytes which determines the file size of the local file. Returns true if succeeded, otherwise false.Parameters:
- path - The path of the collection or file one wants to get - relative to the
rootUrlstated when instantiating the client. - file - The file to save the received data in.
- encoding - The encoding to use when reading the remote file.
- maxFileSize - The maximum number of bytes to stream into the file. Not to exceed MAX_GET_FILE_SIZE.
Returns:
- returns true if succeeded, otherwise false.
- path - The path of the collection or file one wants to get - relative to the
- get(path: String, encoding: String): String
Reads the content of a remote file or directory that can be found under
rootUrl/pathand returns a string representation of the data found in the givenencoding. If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Returns at most DEFAULT_GET_STRING_SIZE bytes.Parameters:
- path - The path of the collection or file one wants to get - relative to the
rootUrlstated when instantiating the client. - encoding - The encoding of the resulting String.
Returns:
- returns the String representation of the data found on the given path in the given encoding.
- path - The path of the collection or file one wants to get - relative to the
- get(path: String, encoding: String, maxGetSize: Number): String
Reads the content of a remote file or directory that can be found under
rootUrl/pathand returns a string representation of the data found in the givenencoding. If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Returns at most maxGetSize bytes.Parameters:
- path - The path of the collection or file one wants to get - relative to the
rootUrlstated when instantiating the client. - encoding - The encoding of the resulting String.
- maxGetSize - The maximum size of data in bytes. Not to exceed MAX_GET_STRING_SIZE.
Returns:
- returns the String representation of the data found on the given path in the given encoding.
- path - The path of the collection or file one wants to get - relative to the
- getAllResponseHeaders(): HashMap
Returns a HashMap of all response headers.
Returns:
- all headers in a HashMap.
- getBinary(path: String, file: File): Boolean
Reads the content of a remote binary file that can be found under
rootUrl/pathand creates a local copy in File. If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Copies at most DEFAULT_GET_FILE_SIZE bytes. Returns true if succeeded, otherwise false.Parameters:
- path - The path relative to
rootUrlon the remote server including the file name. - file - The local file where the received binary data should be stored.
Returns:
- true if succeeded, otherwise false.
- path - The path relative to
- getBinary(path: String, file: File, maxFileSize: Number): Boolean
Reads the content of a remote binary file that can be found under
rootUrl/pathand creates a local copy in File. If the remote location is a directory the result depends on the server configuration, some return an HTML formatted directory listing. Copies at most maxFileSize bytes. Returns true if succeeded, otherwise false.Parameters:
- path - The path relative to
rootUrlon the remote server including the file name. - file - The file local file where the received binary data should be stored.
- maxFileSize - The maximum number of bytes to stream into the file. Not to exceed MAX_GET_FILE_SIZE.
Returns:
- true if succeeded, otherwise false.
- path - The path relative to
- getResponseHeader(header: String): String
Returns a specified response header - multiple headers are separated by CRLF.
Parameters:
- header - The name of the header.
Returns:
- The header - in case of multiple headers separated by CRLF.
- getStatusCode(): Number
Returns the status code after the execution of a method.
Returns:
- the
statusCode.
- the
- getStatusText(): String
Returns the status text after the execution of a method.
Returns:
- the
statusText.
- the
- mkcol(path: String): Boolean
Creates a directory on the remote server on the location
rootUrl/path.Parameters:
- path - The path relative to the
rootUrlstated when instantiating the client where the new collection should be created.
Returns:
- true if succeeded, otherwise false.
- path - The path relative to the
- move(origin: String, destination: String): Boolean
Moves a file on the server from one place
rootUrl+ "/" +originto the otherrootUrl/destination. Ifdestinationalready exists it gets overwritten. Can also be used to rename a remote file. Returns true if succeeded, otherwise false.Parameters:
- origin - The origin where a file is located, relative to the
rootUrlstated when instantiating the client. - destination - The destination where the file should be moved to, relative to the
rootUrlstated when instantiating the client.
Returns:
- true if succeeded, otherwise false.
- origin - The origin where a file is located, relative to the
- move(origin: String, destination: String, overwrite: Boolean): Boolean
Moves a file on the server from one place
rootUrl/originto the otherrootUrl/destinationCan also be used to rename a remote file. Ifoverwriteis true anddestinationalready exists it gets overwritten. Returns true if succeeded, otherwise false.Parameters:
- origin - The origin where a file is located, relative to the
rootUrlstated when instantiating the client. - destination - The destination where the file should be moved to, relative to the
rootUrlstated when instantiating the client. - overwrite - A flag which determines whether the destination gets overwritten if it exists before moving.
Returns:
- true if succeeded, otherwise false.
- origin - The origin where a file is located, relative to the
- options(path: String): String[]
Returns a list of methods which can be executed on the server location
rootUrl/path.Parameters:
- path - The path relative to the
rootUrlstated when instantiating the client one wants to get the options for.
Returns:
- list of WebDav methods which can be executed on the given path.
- path - The path relative to the
- propfind(path: String): WebDAVFileInfo[]
Get file listing of a remote location.
Returns a list of WebDAVFileInfo objects which contain information about the files and directories located on
rootUrl/pathand DEPTH_1 (1) level underneath.Parameters:
- path - The path relative to the
rootUrlstated when instantiating the client where to get information about the containing files from.
Returns:
- an Array of WebDAVFileInfo objects which hold information about the files located on the server at the location.
- path - The path relative to the
- propfind(path: String, depth: Number): WebDAVFileInfo[]
Get file listing of a remote location.
Returns a list of WebDAVFileInfo objects which contain information about the files and directories located on
rootUrl/pathand the passed depth underneath.Parameters:
- path - The path relative to the
rootUrlstated when instantiating the client where to get information about the containing files from. - depth - The level starting from
rootUrldown to which the file information gets collected.
Returns:
- an Array of WebDAVFileInfo objects which hold information about the files located on the server at the location.
- path - The path relative to the
- put(path: String, file: File): Boolean
Puts content out of a passed local file into a remote located file at
rootUrl/path. This method performs a binary file transfer. Returns true if succeeded, otherwise false.Parameters:
- path - The path to put given content up to, relative to the
rootUrlstated when instantiating the client. - file - The file to push up to the server.
Returns:
- true if succeeded, otherwise false.
- path - The path to put given content up to, relative to the
- put(path: String, content: String): Boolean
Puts content encoded with DEFAULT_ENCODING into a remote located file at
rootUrl/path. Returns true if succeeded, otherwise false.If the content of a local file is to be uploaded, please use method put(String, File) instead.
Parameters:
- path - The path to put given content up to, relative to the
rootUrlstated when instantiating the client. - content - The content that has to be pushed on to the server.
Returns:
- true if succeeded, otherwise false.
- path - The path to put given content up to, relative to the
- put(path: String, content: String, encoding: String): Boolean
Puts content encoded with the passed encoding into a remote located file at
rootUrl/path. Returns true if succeeded, otherwise false.If the content of a local file is to be uploaded, please use method put(String, File) instead.
Parameters:
- path - The path to put a given content up to, relative to the
rootUrlstated when instantiating the client. - content - The content that has to be pushed on to a remote location.
- encoding - The encoding in which the data should be stored on the server.
Returns:
- true if succeeded, otherwise false.
- path - The path to put a given content up to, relative to the
- succeeded(): Boolean
Returns true if the last executed WebDAV method was executed successfully - otherwise false. See the code snippet above for an example how to use the succeed() method.
Returns:
- true if the last executed WebDAV method was successful - otherwise false.
See Also: