What are the potential security risks of using FTP over SSH in PHP?

Using FTP over SSH in PHP can potentially expose sensitive information, such as login credentials, to unauthorized users if not properly secured. To mitigate this risk, it is recommended to use SFTP (SSH File Transfer Protocol) instead of FTP over SSH, as SFTP provides a more secure way to transfer files over a network.

// Connect to SFTP server using SSH2
$connection = ssh2_connect('sftp.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');

// Initialize SFTP subsystem
$sftp = ssh2_sftp($connection);

// Download file from SFTP server
$stream = fopen('ssh2.sftp://'.$sftp.'/path/to/file.txt', 'r');
$data = stream_get_contents($stream);
fclose($stream);