Are there any best practices for retrieving file modification dates from a remote server using PHP?

When retrieving file modification dates from a remote server using PHP, it is important to use a secure method such as SSH or FTP to establish a connection and retrieve the information. One common approach is to use the SSH2 extension for PHP to securely connect to the remote server and retrieve file modification dates.

// Connect to remote server using SSH
$connection = ssh2_connect('remote.server.com', 22);
ssh2_auth_password($connection, 'username', 'password');

// Get file modification date
$stream = ssh2_exec($connection, 'stat -c %Y /path/to/file.txt');
stream_set_blocking($stream, true);
$modification_date = trim(stream_get_contents($stream));

// Close SSH connection
ssh2_disconnect($connection);

echo "File modification date: " . date('Y-m-d H:i:s', $modification_date);