Check if the FTP service is running on an Ubuntu server with PHP

You can use the exec() function in PHP to execute a shell command to check the status of the FTP service on a remote server. Here's an example code that uses the systemctl command to check if the FTP service is running on an Ubuntu server:

$server = '192.168.1.100'; // Replace with your server IP
$username = 'username'; // Replace with your server username
$password = 'password'; // Replace with your server password

// SSH connection
$connection = ssh2_connect($server, 22);
ssh2_auth_password($connection, $username, $password);

// Execute systemctl command to check FTP service status
$stream = ssh2_exec($connection, 'systemctl status vsftpd.service');
stream_set_blocking($stream, true);

// Get command output
$output = stream_get_contents($stream);

// Check if FTP service is active
if (strpos($output, 'Active: active (running)') !== false) {
    echo 'FTP service is running.';
} else {
    echo 'FTP service is not running.';
}

// Close SSH connection
ssh2_exec($connection, 'exit');
unset($connection);

Note that this example code uses SSH connection to access the remote server and run the systemctl command. You also need to replace the $server, $username, and $password variables with your own values.

Komentar

Postingan populer dari blog ini

WhatsApp Web login QR code in an HTML page using whatsapp-web.js

Node.js Telegram Bot API send an image with text

Add these security headers to your website