Description
This function recursively searches for a file within a directory.
Warning:
We strongly recommend that you use UAPI instead of cPanel API 2. However, no equivalent UAPI function exists.
Examples
https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=search&dir=%2Fhome%2Fexample&attributes=user%7Cgroupusage%7Csize%7Ctype%7Cmode%7Cctime%7Catime%7Cmtime
$cpanel
=
new
CPANEL();
// Connect to cPanel - only do this once.
// Search for files that begin with /home/example
$search_files
=
$cpanel
->api2(
'Fileman'
,
'search'
,
array
(
'dir'
=>
'home/example'
'attributes'
=>
'user|groupusage|size|type|mode|ctime|atime|mtime'
);
my
$cpliveapi
= Cpanel::LiveAPI->new();
# Connect to cPanel - only do this once.
# Search for files that begin with /home/example
my
$search_files
=
$cpliveapi
->api2(
'Fileman'
,
'search'
,
{
'dir'
=>
'home/example'
'attributes'
=>
'user|groupusage|size|type|mode|ctime|atime|mtime'
}
);
Warning:
In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that youonly use the LiveAPI system to call the cPanel APIs.
cPanel API 2 calls that use cPanel tags vary widely in code syntax and in their output. For more information, read our Deprecated cPanel Tag Usage documentation. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.
cpapi2 --user=username Fileman search dir =home%2Fexample attributes=user%7Cgroupusage%7Csize%7Ctype%7Cmode%7Cctime%7Catime%7Cmtime |
Notes:
- You must URI-encode values.
- username represents your account-level username.
{
"cpanelresult": {
"apiversion": 2,
"func": "search",
"data": [
{
"ctime": 1414597689,
"mtime": 1414597689,
"mode": 457,
"file": "/home/example",
"size": 4096,
"mimeinfo": "homeb",
"groupusage": 64768,
"user": "example",
"type": "dir",
"atime": 1412105321
},
{
"ctime": 1412105376,
"mtime": 1412105376,
"mode": 384,
"file": "/home/example/.lastlogin",
"size": 10,
"mimeinfo": "text-x-generic",
"groupusage": 64768,
"user": "example",
"type": "file",
"atime": 1412105376
},
{
"ctime": 1412233359,
"mtime": 1412233359,
"mode": 416,
"file": "/home/example/cpbackup-exclude.conf",
"size": 1,
"mimeinfo": "text-plain",
"groupusage": 64768,
"user": "example",
"type": "file",
"atime": 1412233359
}
],
"event": {
"result": 1
},
"module": "Fileman"
}
}
Note:
Use cPanel's API Shell interface (Home >> Advanced >> API Shell) to directly test cPanel API calls.
Parameters
Parameter |
Type |
Description |
Possible values |
Example |
dir |
string |
The path to search. This parameter defaults to the home directory. Note: The function also searches this directory's subdirectories if therecursive value is 1. |
Any valid absolute file path. |
/home/user |
attributes |
string |
A list of attributes to return for each result. If you do not use this parameter, the function will not return any attributes. |
Note: Separate multiple attributes with the pipe character (|). |
user|size|type|mode|ctime |
recursive |
Boolean |
Whether to perform the search recursively. This parameter defaults to 0. |
|
1 |
mimeinfo |
Boolean |
Whether to return the mimeinforeturn. This parameter defaults to 1. |
|
1 |
regex |
string |
A Perl Compatible Regular Expression (PCRE) that filters the results. If you do not use this parameter, the function returns information for all of a directory's files. |
A valid PCRE. |
user |
Returns
Return |
Type |
Description |
Possible values |
Example |
atime |
integer |
The file's last accessed time. |
A Unix time stamp. |
1412105376 |
ctime |
integer |
The file's creation time. |
A Unix time stamp. |
1413398577 |
file |
string |
The file's name. |
A valid path and filename. |
/home/example/cpbackup-exclude.conf
|
groupusage |
integer |
The file owner's system group ID. |
A positive integer. |
64768 |
mimeinfo |
string |
The file's MIME type. |
A valid MIME type. |
text-plain |
mode |
integer |
The file's permissions. |
A set of file permissions, in decimal notation format. |
493 |
mtime |
integer |
The file's last modification time. |
A Unix time stamp. |
1413830456 |
size |
integer |
The size of the file. |
A positive integer, in bytes. |
4096 |
type |
string |
The item type. |
|
file |
user |
string |
The file owner's user ID. |
Any valid user ID on the server. |
example |
reason |
string |
A reason for failure Note: This function only returns a reasonvalue if an error occurred. |
A string that describes the error. |
This is an error message. |
result |
Boolean |
Whether the function succeeded. |
|
1 |