PHP ftp_systype() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
FTP

Definition

In PHP, ftp_systype() returns the operating system type of the remote FTP server, such as UNIX.

It sends the SYST command to the server. Knowing the system type helps you decide how to parse listings from ftp_rawlist(), which look different on Unix and Windows servers.

Syntax

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

PHP
$type = ftp_systype($ftp);
CallWhat it does
ftp_systype($ftp)Returns a string such as "UNIX" that describes the server system.
ftp_systype($ftp) === 'UNIX'Checks whether the server is a Unix style system.
ftp_systype($ftp) === falseTests whether the server could not report its type.

The returned text comes straight from the server, so the exact words can vary. Common values are UNIX and Windows_NT. Some servers hide this information on purpose.

Library declarations
PHP
ftp_systype(FTP\Connection $ftp): string|false

Parameters

ParameterDescription
ftpRequired. The FTP connection returned by ftp_connect() or ftp_ssl_connect(). You should already be logged in.

Return Value

Return ValueDescription
string|falseReturns the system type as a string, or false on failure.

PHP Examples

Example 1 — Show the Server System Type

Log in and print the type of system the FTP server reports.

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

echo "Server type: ", ftp_systype($ftp), PHP_EOL;

ftp_close($ftp);

How It Works

  1. The connection is opened and you log in.
  2. ftp_systype() sends the SYST command to the server.
  3. The server replies with its system type, here UNIX.
  4. echo prints the answer on the screen.

Example 2 — Handle a Server That Will Not Say

ftp_systype() can return false, so check the value before using it.

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

$type = ftp_systype($ftp);

if ($type === false) {
    echo "System type unknown", PHP_EOL;
} else {
    echo "System type: $type", PHP_EOL;
}

ftp_close($ftp);

How It Works

  1. The result of ftp_systype() is stored in $type.
  2. A false value means the server refused or failed to answer.
  3. The strict === comparison avoids mixing up false with an empty string.
  4. Here the server answered normally, so the type is printed.

Example 3 — Choose a Listing Style

Use the system type to decide how you will read the output of ftp_rawlist().

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

$type = ftp_systype($ftp);

if ($type === 'UNIX') {
    echo "Use the Unix ls -l style parser", PHP_EOL;
} elseif (stripos((string) $type, 'windows') !== false) {
    echo "Use the Windows dir style parser", PHP_EOL;
} else {
    echo "Unknown style, try ftp_mlsd()", PHP_EOL;
}

ftp_close($ftp);

How It Works

  1. ftp_systype() tells us what kind of system the server is.
  2. A Unix server returns listings like the ls -l command.
  3. stripos() looks for the word windows without caring about letter case.
  4. If the type is unknown, ftp_mlsd() is a cleaner way to read a listing.

Frequently Asked Questions

It returns the operating system type of the FTP server, such as UNIX, by sending the SYST command.
It returns false. Check the result with === false before you use it.
Mostly for reading ftp_rawlist() output. Unix servers and Windows servers format listings differently, so the type tells you which parser to use.
No. The server decides what it says, and some servers hide it. Treat the value as a hint only.
Yes, it is best to call ftp_login() first. Many servers do not answer commands before authentication.

Back to FTP Functions

Browse all PHP FTP function tutorials.

FTP functions →

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