cPanel API 2 Functions - Fileman::viewfile

Warning:

The cPanel API 2 system is deprecated. We strongly recommend that you use UAPI instead of cPanel API 2.

Description

This function lists file information.

Warning:

We strongly recommend that you use the following UAPI function instead of this function:

Important:

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


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:
  • 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 include the --user=username option.
  • 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

Parameter Type Description Possible values Example
dir string

The path to the file's directory.

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

Required

The file's name.

A valid file name.

Separate multiple files with the pipe character (|).

file.html

Returns

Return Type Description Possible values Example
mode string The file's permissions. A set of file permissions, in textual representation format. 33188
file string The file's name. A valid filename. file.html
rawmimetype string The file's MIME type. A valid MIME type. text/html
nicemode integer The file's permissions. A set of file permissions, in octal notation format. 0777
size integer The size of the file. A positive integer, in bytes. 4096
humansize string The formatted size of the file. A positive integer, in megabytes (MB), kilobytes (KB), or gigabytes (GB). 4 KB
group string The file owner's system group name. A valid group name. example
fullpath string

The absolute path to the file.

A valid absolute file path. /home/example/public_html/file.html
user string The file owner's system user name. A valid system username. example
ctime integer The file's creation time. A Unix time stamp. 1371711650
uid integer The file owner's user ID.

A valid user ID on the server.

517
mtime integer The file's last modification time. A Unix time stamp. 1411211655
mimename string The file's MIME name. A valid MIME name. text-html
path string

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
mimeinfo string The file's MIME type. A valid MIME type. text/html
rawmimename string The file's MIME name. A valid MIME name. text-html
absdir string The absolute path to the directory. A valid directory, relative to the account's /home directory. home/user/public_html
type string The type of the item.
  • file
  • dir
  • char
  • block
  • fifo
  • link
  • socket
file
gid integer The file owner's system group ID. A valid group ID. 508
reason string

A reason for failure.

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

A string that describes the error. This is an error message.
result Boolean

Whether the function succeeded.

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