PHP ftp_site() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
FTP

Definition

In PHP, ftp_site() sends a SITE command to the FTP server. SITE commands are server specific extras that are not part of the basic FTP protocol.

A common example is SITE CHMOD, which changes file permissions on many Unix servers. The commands you can use depend entirely on the server software.

Syntax

Call ftp_site() with the values you need. Start with this line.

PHP
$ok = ftp_site($ftp, 'CHMOD 0644 index.html');
CallWhat it does
ftp_site($ftp, 'CHMOD 0644 index.html')Asks the server to set the permissions of index.html to 0644.
ftp_site($ftp, 'HELP')Asks the server to list the SITE commands it supports.
ftp_site($ftp, 'UMASK 022')Sets the default permission mask on servers that support it.

ftp_site() only returns true or false. It does not give you the text of the server reply. If you need the reply lines, use ftp_raw() with the command SITE ... instead.

Library declarations
PHP
ftp_site(FTP\Connection $ftp, string $command): bool

Parameters

ParameterDescription
ftpRequired. The FTP connection returned by ftp_connect() or ftp_ssl_connect(). You should already be logged in.
commandRequired. The SITE command to run, written without the leading word SITE, for example CHMOD 0644 file.txt.

Return Value

Return ValueDescription
boolReturns true on success or false on failure.

PHP Examples

Example 1 — Change Permissions with SITE CHMOD

Use ftp_site() to set a file to 0644 on the server.

PHP
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');

if (ftp_site($ftp, 'CHMOD 0644 index.html')) {
    echo "Permissions updated", PHP_EOL;
} else {
    echo "SITE command failed", PHP_EOL;
}

ftp_close($ftp);

How It Works

  1. You do not type the word SITE yourself. ftp_site() adds it for you.
  2. The command CHMOD 0644 index. html is sent to the server.
  3. A supporting server changes the permissions and replies with success.
  4. ftp_site() returns true and the message is printed.

Example 2 — An Unsupported SITE Command

If the server does not know the command, ftp_site() returns false.

PHP
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');

$ok = @ftp_site($ftp, 'MAKEITFAST now');

echo $ok ? "Done" : "The server does not support this command", PHP_EOL;

ftp_close($ftp);

How It Works

  1. MAKEITFAST is a made up command that no server knows.
  2. The server replies with an error such as 500 Unknown SITE command.
  3. ftp_site() turns that error reply into false.
  4. The ternary operator prints a friendly message instead of a warning.

Example 3 — Read the Reply with ftp_raw()

When you want to see what the server says, send the SITE command through ftp_raw() instead.

PHP
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');

$reply = ftp_raw($ftp, 'SITE HELP');

foreach ($reply as $line) {
    echo trim($line), PHP_EOL;
}

ftp_close($ftp);

How It Works

  1. ftp_raw() needs the full command, so SITE is written out this time.
  2. The server answers with several lines describing the SITE commands it supports.
  3. foreach prints each line after trim() removes extra spaces.
  4. This shows which commands you can safely use with ftp_site().

Frequently Asked Questions

It sends a SITE command to the FTP server. These are extra commands that depend on the server, such as CHMOD or UMASK.
No. ftp_site() adds it for you. Pass only the rest, for example CHMOD 0644 file.txt.
ftp_site() only returns true or false. Use ftp_raw($ftp, 'SITE ...') if you want the reply text.
Use ftp_chmod() for changing permissions. It is made for that job and does not depend on server specific text commands.
The server may not support the command, the file may not exist, or you may not have permission to run it.

Next: ftp_size()

ftp_size() returns the size of a remote file in bytes.

ftp_size() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful