What are the potential pitfalls of using FTP/SFTP for transferring data between servers in a PHP script?
One potential pitfall of using FTP/SFTP for transferring data between servers in a PHP script is the lack of encryption and security vulnerabilities. To mitigate this risk, it is recommended to use a secure method such as SSH/SFTP instead of FTP.
// Example of transferring data between servers using SSH/SFTP in PHP
$localFile = '/path/to/local/file.txt';
$remoteFile = '/path/to/remote/file.txt';
$connection = ssh2_connect('remote-server.com', 22);
ssh2_auth_password($connection, 'username', 'password');
ssh2_scp_send($connection, $localFile, $remoteFile);