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_raw() function in PHP
The ftp_raw() function sends raw commands directly to the FTP server and returns the server's response. This gives you low-level control over FTP operations by allowing you to send any valid FTP protocol command.
Syntax
ftp_raw(connection, command)
Parameters
connection − The FTP connection resource created by
ftp_connect()command − The raw FTP command to execute (without trailing CRLF)
Return Value
The ftp_raw() function returns the server's response as an array of strings, where each element represents a line of the server's response.
Example
The following example demonstrates sending raw FTP commands ?
<?php
$ftp_server = "192.168.0.4";
$con = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
// Send raw authentication commands
$response1 = ftp_raw($con, "USER david");
$response2 = ftp_raw($con, "PASS yourpassword");
// Display server responses
print_r($response1);
print_r($response2);
// Get current working directory using raw command
$pwd_response = ftp_raw($con, "PWD");
print_r($pwd_response);
// Close connection
ftp_close($con);
?>
Array
(
[0] => 331 Password required for david.
)
Array
(
[0] => 230 User david logged in.
)
Array
(
[0] => 257 "/" is current directory.
)
Common Use Cases
Use ftp_raw() when you need to send FTP commands not directly supported by PHP's built-in FTP functions, such as SITE commands, STAT, or custom server-specific commands.
Conclusion
The ftp_raw() function provides direct access to FTP protocol commands and returns server responses as arrays. It's useful for advanced FTP operations not covered by standard PHP FTP functions.
