PHP Function Reference

PHP ftp_raw() Function



The PHP ftp_raw() function is used to send a raw command to the FTP server.

Syntax

ftp_raw(ftp, command)

Parameters

ftp Required. Specify the FTP connection to use.
command Required. Specify the command to execute.

Return Value

Returns the server's response as an array of strings. No parsing is performed on the response string, nor does this function determines if the command succeeded.

Example:

The example below shows the usage of ftp_raw() function.

<?php
//FTP server to use
$ftp_server = "ftp.example.com";
   
//set up a connection or die 
$ftp = ftp_connect($ftp_server)
    or die("Could not connect to $ftp_server");
   
if($ftp) {
  echo "Successfully connected to $ftp_server!\n";
 
  //trying to login - the two lines below is same
  //as ftp_login($ftp_conn,"John123","password");
  ftp_raw($ftp_conn, "USER John123");
  ftp_raw($ftp_conn, "PASS password");

  //close the connection
  if(ftp_close($ftp)) {
    echo "Connection closed successfully!\n"; 
  } 
}
?>

The output of the above code will be:

Successfully connected to ftp.example.com!
Connected as user@ftp.example.com
Connection closed successfully!

❮ PHP FTP Reference