Child pages
  • cPanel API 2 Functions - Fileman::search

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

Excerpt
This function recursively searches for a file within a directory.

Include Page
LIB:_cPanelAPI2NoEquivalent
LIB:_cPanelAPI2NoEquivalent

Multiexcerpt include
SpaceWithExcerptcom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@12665
MultiExcerptNameAPIDisabledFileStorageRole
PageWithExcerptLIB:_ServerRoleDisabledAPI

Panel
bgColor#F2F2F2
borderStylenone

Examples 


Panel
bgColor#FFFFFF
borderStylenone


Expand
titleWHM API (JSON)


Code Block
languagetext
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

Include Page
LIB:_CallFromWHMAPILink
LIB:_CallFromWHMAPILink


Expand
titleLiveAPI PHP Class


Code Block
languagephp
linenumberstrue
$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'
);

Include Page
LIB:_LiveAPIPHPLink
LIB:_LiveAPIPHPLink

 


Expand
titleLiveAPI Perl Module


Code Block
languageperl
linenumberstrue
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'
	}	
 );

Include Page
LIB:_LiveAPIPerlLink
LIB:_LiveAPIPerlLink

 


Expand
titlecPanel Tag System (deprecated)

Include Page
LIB:_cPanelAPI2cPanelTagsWarning
LIB:_cPanelAPI2cPanelTagsWarning


Expand
titleCommand Line


Code Block
languagebash
cpapi2 --user=username Fileman search dir=home%2Fexample attributes=user%7Cgroupusage%7Csize%7Ctype%7Cmode%7Cctime%7Catime%7Cmtime

Include Page
LIB:_cPanelAPI2CLINote
LIB:_cPanelAPI2CLINote


Expand
titleOutput (JSON)


Code Block
languagetext
linenumberstrue
{
  "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"
  }
}
  


Include Page
LIB:_cPanelAPIShellNote
LIB:_cPanelAPIShellNote


Parameters

ParameterTypeDescriptionPossible valuesExample

dir

string

The path to search.

This parameter defaults to the home directory.

Note
titleNote:

The function also searches this directory's subdirectories if the recursive value is 1.


Any valid absolute file path./home/user
attributesstring

A list of attributes to return for each result.

If you do not use this parameter, the function will not return any attributes.

  • user — Search for the file's owner's name.
  • groupusage — Search for the file's group's name.
  • size — Search for the file size.
  • type — Search for the file type.
  • mode — Search for the file's permissions.
  • ctime — Search for the file's creation time.
  • atime — Search for the last time that the file was accessed.
  • mtime — Search for the last time that the file was modified.
Note
titleNote:

Separate multiple attributes with the pipe character (|).


user|size|type|mode|ctime
recursiveBoolean

Whether to perform the search recursively.

This parameter defaults to 0.

  • 1 — Search recursively.
  • 0 — Do not search recursively.
1
mimeinfoBoolean

Whether to return the mimeinfo return.

This parameter defaults to 1.

  • 1 — Return the mimeinfo return for each result.
  • 0 — Do not return the mimeinfo return for each result.
1
regexstring

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

ReturnTypeDescriptionPossible valuesExample
atimeintegerThe file's last accessed time.A Unix time stamp.1412105376
ctimeintegerThe file's creation time.

A Unix time stamp.

1413398577
filestringThe file's name.A valid path and filename.
/home/example/cpbackup-exclude.conf
              
groupusageintegerThe file owner's system group ID.A positive integer.
64768
mimeinfostringThe file's MIME type.A valid MIME type.text-plain
modeintegerThe file's permissions.A set of file permissions, in decimal notation format.
493
mtimeintegerThe file's last modification time.A Unix time stamp.1413830456
sizeintegerThe size of the file.A positive integer, in bytes.4096
typestringThe item type.
  • file
  • dir
  • char
  • block
  • fifo
  • link
  • socket
file
userstringThe file owner's user ID.Any valid user ID on the server.example
reasonstring

A reason for failure

Note
titleNote:

This function only returns a reason value if an error occurred.


A string that describes the error.This is an error message.
resultBoolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1