cPanel/Fileman
cPanel module

Fileman

8 functions, invoked through the cpanel_uapi tool.

scope cpanel:uapi
Call any function with cpanel_uapi(service_id, module="Fileman", function, params). Live availability depends on the cPanel features JetHost has enabled on your account — call list_cpanel_operations to see what is active.

autocompletedir GET#

Return autocomplete file and directory names

This function returns any files and directories that begin with a specified string.

Important:

When you disable the File Storage role, the system disables this function.

pathstringRequired
The prefix of the paths to complete.
dirsonlyintegerOptional
Whether to include only directories in the output. 1Only include directories. 0 — Include directories and files.
htmlintegerOptional
Whether to return HTML-encoded results. 1 — Return HTML-encoded output. 0 — Return plaintext output.
list_allintegerOptional
Whether to return all files and directories inside the specified directory. If you set this parameter's value to 1, you must set the path parameter's value to a full directory path. 1 — Return all files and directories inside the specified directory. 0 — Return partial file and directory name matches.

Response — normalized as { ok, data, errors[], warnings[] }; data is an array of:

filestring
A file or directory that matches the specified path.

empty_trash GET#

Delete .trash folder content

This function purges content from the .trash folder in the user's home directory.

Important:

When you disable the FileStorage role, the system disables this function.

older_thanintegerOptional
The maximum age in days of content that the function will not purge. Note: A value of 0 will purge everything from the user's .trash folder.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

Payload varies by call.

get_file_content GET#

Return file content

This function retrieves a file's content.

Important:

When you disable the File Storage role, the system disables this function.

Note:

JSON strings must be valid UTF-8. To retrieve a non-UTF-8 file via JSON, we recommend that you give ISO-8859-1 as from_charset and UTF-8 as to_charset, then decode the return payload’s content as UTF-8.

dirstringRequired
The file path to the directory that contains the selected file.
filestringRequired
The file to retrieve.
from_charsetstringOptional
The file’s character encoding. This parameter defaults to _DETECT_, which indicates a request to detect the file’s character encoding.
to_charsetstringOptional
The output character encoding. This parameter defaults to _LOCALE_, which indicates a request to use the session locale’s character encoding. Important: Contexts that serialize the API response as JSON require this value to be utf-8 or US-ASCII. Behavior is undefined if the request indicates any other encoding.
update_html_document_encodingintegerOptional
Whether to update the file's HTML document encoding. 1 — Update the file's HTML document encoding. 0 — Don't update the file's HTML encoding.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

contentstring
The file's contents. A string value. Note: Behavior is undefined if the calling context requires an encoding that conflicts with the file contents. For example, if the file contents are ISO-8859-1 but the context requires UTF-8 (as is the case with JSON), the system may apply an extra layer of UTF-8 encoding in order to satisfy the request.
dirstring
The absolute path to the directory that contains the selected file.
filenamestring
The file's name.
from_charstring
The file's previous character encoding. If the request’s from_charset was _DETECT_, this will contain the detected encoding. Otherwise, it will contain the request’s from_charset value.
from_charsetany
pathstring
The absolute path to the file.
to_charstring
The file's new character encoding. If the request’s from_charset was _LOCALE_, this will contain the locale’s encoding. Otherwise, it will contain the request’s to_charset value.
to_charsetany

get_file_information GET#

Return file or directory information

This function returns the information for a specified file or directory.

Important:

When you disable the File Storage role, the system disables this function.

pathstringRequired
The directory from which to list files.
check_for_leaf_directoriesintegerOptional
Whether to flag directories that contain subdirectories. 1 - Flag directories that contain subdirectories. 0 - Do not flag directories that contain subdirectories.
include_mimeintegerOptional
Whether to return the file's MIME type. 1 - Return the file's MIME type. 0 - Do not return the file's MIME type.
include_permissionsintegerOptional
Whether to parse the file owner's read and write permissions. 1 - Parse the file owner's read and write permissions. 0 - Do not parse the file owner's read and write permissions.
show_hiddenintegerOptional
Whether to include hidden files in the output. 1 - Include hidden files. 0 - Do not include hidden files.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

absdirstring
The path to the user's home directory.
ctimeinteger
The file's creation time, Unix time format.
existsinteger
Whether the file exists in the directory. 1 - Exists. 0 - Does not exist.
One of: 0 1
filestring
The filename.
fullpathstring
The file's full filepath.
gidinteger
The file owner's system group ID.
humansizestring
The file's formatted size, followed by one of the following symbols: KB - kilobytes MB - megabytes * GB - gigabytes
isleafinteger
Whether the directory contains subdirectories. 1 - Contains subdirectories. 0 - Does not contain subdirectories.
One of: 0 1
mimenamestring
The file's MIME name.
mimetypestring
The file's MIME type.
modestring
The file's textual permissions in Unix format.
mtimeinteger
The file's last modification time, in Unix time format.
nicemodeinteger
The file's numerical permissions in octal notation.
pathstring
The file's path.
rawmimenamestring
The file's raw MIME name.
rawmimetypestring
The file's raw MIME type.
readinteger
Whether the file is readable. The function only returns this value if you set the include_permissions value to 1. 1 - Readable. 0 - Not readable.
One of: 0 1
sizeinteger
The file's size, in bytes.
typestring
The item's type. file - File. dir - Directory. char - Character special device. block - Block special device. fifo - Named pipe. link - Symbolic link. * socket - Unix domain socket.
One of: file dir char block fifo link socket
uidinteger
The file owner's system user ID.
writeinteger
Whether the file is writable. The function only returns this value if you set the include_permissions value to 1 . 1 - Writable. 0 - Not writable.
One of: 0 1

list_files GET#

Return directory content

This function returns a sorted list of files and directories.

Important:

When you disable the FileStorage role, the system disables this function. For more information, read our How to Use Server Profiles documentation.

dirstringRequired
The directory from which to list files.
check_for_leaf_directoriesintegerOptional
Whether to return directories that contain subdirectories. 1 — Return subdirectories. 0 — Do not retain subdirectories.
include_mimeintegerOptional
Whether to return the file's MIME type. 1 — Include MIME type. 0 — Do not include MIME type. Note: If you set this value to 0 but also include the mime_types or raw_mime_types parameters, the function overrides your specified value and sets this parameter to 1.
include_permissionsintegerOptional
Whether to parse the file owner's read and write permissions. 1 — Parse file permissions. 0 — Do not parse file permissions.
limit_to_listintegerOptional
Whether to return only entries that begin with the filepath- prefix. 1 — Return only files that begin with the filepath- prefix. 0 — Return all files. If you do not use this parameter, the function returns all filenames.
mime_typesstringOptional
The MIME types to return. If you use this parameter, the function returns the specified MIME types and sets the include_mime parameter's value to 1. If you do not use this parameter, the function returns all MIME types.
only_these_filesstringOptional
A comma-separated list of files to return. If you do not use this parameter, the function returns all files.
raw_mime_typesstringOptional
The raw MIME types to return. If you use this parameter, the function returns the specified MIME types and sets the include_mime parameter's value to 1. If you do not use this parameter, the function returns all MIME types.
show_hiddenintegerOptional
Whether to include hidden files in the output. 1 — Include hidden files. 0 — Do not include hidden files.
typesarray<any>Optional
A pipe-separated list of file types to return. file — A file. dir — A directory. char — A character special device. block — A block special device. fifo — A named pipe (FIFO). link — A symbolic link. * socket — A Unix domain socket. If you do not use this parameter, the function returns all file types.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

dirsarray<object>
An array of objects containing information about each directory.
absdirstring
The file path to the user's home directory.
ctimeinteger
The directory's creation date.
existsinteger
Whether the directory exists in the directory. 1 — Exists. 0 — Does not exist.
One of: 0 1
filestring
The directory name.
fullpathstring
The directory's full directory path.
gidinteger
The directory owner's system group ID.
humansizestring
The formatted size of the directory. The function returns the size with one of the following symbols: KB — Kilobytes. MB — Megabytes. * GB — Gigabytes.
isleafinteger
Whether the directory contains subdirectories. 1 — Contains subdirectories. 0 — Does not contain subdirectories.
One of: 0 1
isparentinteger
Whether the directory is a parent record. 1 — A parent record. 0Not a parent record.
One of: 0 1
mimenamestring
The MIME type's name.
mimetypestring
The directory's MIME's type.
modestring
The directory's textual permissions in Unix format.
mtimeinteger
The directory's last modification time.
nicemodeinteger
The directory's numerical permissions.
pathstring
The path to the directory.
rawmimenamestring
The directory's raw MIME type's name.
rawmimetypestring
The directory's raw MIME type.
readinteger
Whether the directory is readable. 1 — Readable. 0Not readable. Note: The function only returns this value if the include_permissions value is 1.
One of: 0 1
sizeinteger
The directory's size, in bytes.
typestring
The item's type. file — A file. dir — A directory. char — A character special device. block — A block special device. fifo - A named pipe (FIFO). link — A symbolic link. * socket — A Unix domain socket.
One of: file dir char block fifo link socket
uidinteger
The directory owner's system user ID.
writeinteger
Whether the directory is writable. 1 — Writable. 0Not writable. Note: The function only returns this value if the include_permissions value is 1.
One of: 0 1
filesarray<object>
An array of objects containing information about each file.
absdirstring
The file path to the user's home directory.
ctimeinteger
The file's creation time.
existsinteger
Whether the file exists in the directory. 1 — Exists. 0 — Does not exist.
One of: 0 1
filestring
The filename.
fullpathstring
The file's full file path.
gidinteger
The file owner's system group ID.
humansizestring
The formatted size of the file. The function returns the size with one of the following symbols: KB — Kilobytes. MB — Megabytes. * GB — Gigabytes.
isleafinteger
Whether the directory contains subdirectories. 1 — Contains subdirectories. 0 — Does not contain subdirectories.
One of: 0 1
isparentinteger
Whether the file is a parent record. 1 — A parent record. 0Not a parent record.
One of: 0 1
mimenamestring
The file's MIME type name.
mimetypestring
The file's MIME type.
modestring
The file's textual permissions.
mtimeinteger
The file's last modification time.
nicemodeinteger
The file's numerical permissions.
pathstring
The absolute path to the file.
rawmimenamestring
The file's raw MIME type's name.
rawmimetypestring
The file's raw MIME type.
readinteger
Whether the file is readable. 1 — Readable. 0Not readable. Note: The function only returns this value if the include_permissions value is 1.
One of: 0 1
sizeinteger
The file's size, in bytes.
typestring
The item's type. file — A file. dir — A directory. char — A character special device. block — A block special device. fifo - A named pipe (FIFO). link — A symbolic link. * socket — A Unix domain socket.
One of: file dir char block fifo link socket
uidinteger
The file owner's system user ID.
writeinteger
Whether the file is writable. 1 — Writable. 0Not writable. Note: The function only returns this value if the include_permissions value is 1.
One of: 0 1

save_file_content GET#

filestringRequired
The files to retrieve.
contentstringOptional
The new file's contents. If you do not use this parameter, the function creates a blank file. JetHost note: a WAF on the API request path REJECTS any call whose content contains the literal <?php (case-insensitive) — it fails as a transport-level error, NOT an {ok:false} result. Plain text and PHP files that open with the short tag <? or <?= pass through (short tags execute only where short_open_tag=On). To deploy PHP source reliably, use deploy_private_repo (git + .cpanel.yml), which clones over SSH and bypasses this request path.
dirstringOptional
The directory that contains the selected file. Note: This parameter defaults to the currently-authenticated user's /home directory. JetHost note: this function cannot create parent directories, and Fileman exposes no delete / copy / move / mkdir function — the target directory must already exist.
fallbackintegerOptional
Whether the function will return an error or save in the default character set if it cannot save in the specified character set. 1 — Save in the default character set. 0 — Return an error.
from_charsetstringOptional
The character set encoding of the content parameter's value.
to_charsetstringOptional
The character set encoding in which to encode the file.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

from_charsetstring
The file's character set.
pathstring
The path to the file.
to_charsetstring
The file's new character set.

transcode GET#

Update buffer encoding

This function converts a buffer from one encoding language to another.

Important:

When you disable the File Storage role, the system disables this function.

contentstringRequired
The file's contents.
discard_illegalintegerOptional
Whether to discard any characters that do not transcode correctly. 1 - Discard invalid characters. 0 - Transcode invalid characters in the default character set encoding.
from_charsetstringOptional
The file's current character set encoding.
to_charsetstringOptional
The character set encoding in which to encode the file.
transliterateintegerOptional
Whether to transcode invalid characters to valid characters in the new character set encoding. 1 - Transcode invalid characters in the new character set encoding. 0 - Return an error message.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

charsetstring
The file's new character set.
contentstring
The file's content.

upload_files GET#

Upload files

This function uploads files.

Note:

For more information about how to use this function in your custom code, read our Use UAPI's Fileman::upload_files Function in Custom Code tutorial.

Important:

When you disable the File Storage role, the system disables this function.

You cannot call this function through WHM API 1's uapi_cpanel function.

No parameters.

Response — normalized as { ok, data, errors[], warnings[] }; data contains:

contentstring
filenamestring
The file's name.