In PHP, ftp_raw() sends a raw FTP command to the server and gives you the reply as an array of lines.
Most tasks have a ready-made function such as ftp_mkdir() or ftp_size(). When you need a command that PHP does not wrap, like FEAT or NOOP, ftp_raw() lets you send it yourself.
Syntax
Call ftp_raw() with the values you need. Start with this line.
PHP
$reply = ftp_raw($ftp, 'NOOP');
Call
What it does
ftp_raw($ftp, 'NOOP')
Sends a harmless no-operation command, often used to keep a connection alive.
ftp_raw($ftp, 'PWD')
Sends the PWD command and returns the server reply, for example 257 "/" is the current directory.
ftp_raw($ftp, 'FEAT')
Asks the server which extra features it supports.
ftp_raw() does not interpret the reply for you. You get the plain text lines from the server, and the first three characters of each line are the FTP status code, such as 200 or 550.
FEAT is a standard command that asks the server what it supports.
ftp_raw() returns every line of the answer as an array item.
foreach goes through each line and trim() removes extra spaces.
The list shows features like MDTM and SIZE, which match PHP functions such as ftp_mdtm() and ftp_size().
Frequently Asked Questions
It sends any raw FTP command to the server and returns the reply as an array of text lines. It is useful for commands PHP does not have a function for.
Each line starts with a three digit status code. For example 200 means success and 550 means the action was refused. Read the code first, then the message.
No, avoid it. Passing user input directly could let someone run unwanted FTP commands. Always validate or whitelist the command first.
Use the dedicated functions like ftp_mkdir(), ftp_delete() or ftp_size() whenever they exist. Use ftp_raw() only when no matching PHP function is available.
ftp_raw() sends any command and returns the reply, while ftp_site() sends a SITE command and only returns true or false.