Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
ftp_site() function in PHP
The ftp_site() function sends an FTP SITE command to the FTP server. These commands are server-specific and handle OS features like file permissions and group membership.
Syntax
ftp_site(conn, command);
Parameters
conn − The FTP connection resource returned by
ftp_connect()command − The SITE command string. These commands vary from server to server and are used for handling OS specific features such as file permissions and group membership
Return Value
The ftp_site() function returns TRUE on success or FALSE on failure.
Example
The following example demonstrates changing file permissions using the SITE command −
<?php
$ftp_server = "192.168.0.4";
$ftp_user = "username";
$ftp_pass = "gfhgfj236k";
$conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($conn, $ftp_user, $ftp_pass);
if (ftp_site($conn, "chmod 777 myfile.txt")) {
echo "Command executed successfully!";
} else {
echo "Command failed to execute!";
}
// close connection
ftp_close($conn);
?>
Command executed successfully!
Common SITE Commands
| Command | Description |
|---|---|
chmod 755 filename |
Change file permissions |
chgrp group filename |
Change group ownership |
umask 022 |
Set default file creation mask |
Conclusion
The ftp_site() function provides access to server-specific FTP commands for advanced file management operations. Always verify command support with your FTP server before implementation.
