Child pages
  • cPanel API 2 Functions - Fileman::viewfile
Skip to end of metadata
Go to start of metadata

Description

This function lists file information.

Warning:

This function is deprecated as of cPanel version 11.40+. We strongly recommend that you use the following UAPI function instead of this function:

Important:

In cPanel & WHM version 76 and later, when you disable the FileStorage role, the system disables this function. For more information, read our How to Use Server Profiles documentation.

Examples 


 WHM API (JSON)
https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=statfiles&dir=public_html&files=file.html%7Cfile2.html%7Cfile3.php


Note:

 For more information, read our Calls from the WHM API documentation.

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// List information about specific files in /home/user/public_html.
$stat_files = $cpanel->api2(
    'Fileman', 'statfiles', 
		array(
		'dir' 				=> 'public_html'
		'files'				=> 'file.html|file2.html|file3.php'
 ) 
);


Note:

For more information, read our Guide to the LiveAPI System.

 

 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# List information about specific files in /home/user/public_html.
my $stat_files = $cpanel->api2(
    'Fileman', 'statfiles', 
	{
		'dir' 				=> 'public_html'
		'files'				=> 'file.html|file2.html|file3.php'
 );


Note:

For more information, read our Guide to the LiveAPI System.

 cPanel Tag System (deprecated)


Warnings:

  • In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that you only use the LiveAPI system to call the cPanel APIs. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.
  • cPanel API 2 calls that use cPanel tags vary in code syntax and in their output.
  • For more information, read our Deprecated cPanel Tag Usage documentation.

 Command Line
cpapi2 --user=username Fileman statfiles dir=public_html files=file.html%7Cfile2.html%7Cfile3.php


Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • You must run the --user=username command.
  • For more information and additional output options, read our Guide to cPanel API 2 documentation or run the cpapi2 --help command.
  • If you run CloudLinux™, you must use the full path of the cpapi2 command:

    /usr/local/cpanel/bin/cpapi2

 Output (JSON)
{
  "cpanelresult": {
    "apiversion": 2,
    "func": "statfiles",
    "data": [
      {
        "mode": 33188,
        "file": "file.html",
        "rawmimetype": "text/html",
        "nicemode": "0644",
        "size": "",
        "humansize": "0 bytes",
        "group": "example",
        "fullpath": "/home/example/public_html/file.html",
        "user": "example",
        "ctime": 1414609879,
        "uid": 517,
        "mtime": 1414609879,
        "mimename": "text-html",
        "path": "/home/example/public_html",
        "mimeinfo": "text\/html",
        "rawmimename": "text-html",
        "absdir": "/home/example/public_html",
        "type": "file",
        "exists": 1,
        "gid": 517
      },
      {
        "mode": 33188,
        "file": "file2.html",
        "rawmimetype": "text\/html",
        "nicemode": "0644",
        "size": "",
        "humansize": "0 bytes",
        "group": "example",
        "fullpath": "/home/example/public_html/file2.html",
        "user": "example",
        "ctime": 1414609890,
        "uid": 517,
        "mtime": 1414609890,
        "mimename": "text-html",
        "path": "/home/example/public_html",
        "mimeinfo": "text/html",
        "rawmimename": "text-html",
        "absdir": "/home/example/public_html",
        "type": "file",
        "exists": 1,
        "gid": 517
      },
      {
        "mode": 33188,
        "file": "file3.php",
        "rawmimetype": "text/x-generic",
        "nicemode": "0644",
        "size": "",
        "humansize": "0 bytes",
        "group": "example",
        "fullpath": "/home/example/public_html/file3.php",
        "user": "example",
        "ctime": 1414609900,
        "uid": 517,
        "mtime": 1414609900,
        "mimename": "text-x-generic",
        "path": "/home/example/public_html",
        "mimeinfo": "text/x-generic",
        "rawmimename": "text-x-generic",
        "absdir": "/home/example/public_html",
        "type": "file",
        "exists": 1,
        "gid": 517
      }
    ],
    "event": {
      "result": 1
    },
    "module": "Fileman"
  }
}


Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
dirstring

The path to the file's directory.

A valid directory path, relative to the user's home directory.public_html/my_directory
filesstring

Required

The file's name.

A valid file name.

Note:

Separate multiple files with the pipe character (|).

file.html

Returns

ReturnTypeDescriptionPossible valuesExample
modestringThe file's permissions.A set of file permissions, in textual representation format.
33188
filestringThe file's name.A valid filename.file.html
rawmimetypestringThe file's MIME type.A valid MIME type.
text/html
nicemodeintegerThe file's permissions.A set of file permissions, in octal notation format.
0777
sizeintegerThe size of the file.A positive integer, in bytes.4096
humansizestringThe formatted size of the file.A positive integer, in Megabytes (MB), Kilobytes (KB), or Gigabytes (GB).4 KB
groupstringThe file owner's system group name.A valid group name.example
fullpathstring

The absolute path to the file.

A valid absolute file path.
/home/example/public_html/file.html
userstringThe file owner's system user name.A valid system username.example
ctimeintegerThe file's creation time.A Unix time stamp.1371711650
uidintegerThe file owner's user ID.

A valid user ID on the server.

517
mtimeintegerThe file's last modification time.A Unix time stamp   .
                1411211655
              
mimenamestringThe file's MIME name.A valid MIME name.
text-html
pathstring

The absolute path to the file.

A valid absolute file path.

This value does not include the file or directory name.

/home/example/public_html
mimeinfostringThe file's MIME type.A valid MIME type.
text/html
rawmimenamestringThe file's MIME name.A valid MIME name.
text-html
absdirstringThe absolute path to the directory.A valid directory, relative to the account's /home directory. home/user/public_html
typestringThe type of the item.
  • file
  • dir
  • char
  • block
  • fifo
  • link
  • socket
file
gidintegerThe file owner's system group ID.A valid group ID.508
reasonstring

A reason for failure.

Note:

This function only returns a reason value if there was an error.

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