What potential pitfalls should be considered when using FTP to transfer files between servers in PHP?

One potential pitfall when using FTP to transfer files between servers in PHP is the security vulnerability of storing FTP credentials directly in the code. To mitigate this risk, consider storing the credentials in a separate configuration file outside of the web root directory.

// Include a separate configuration file with FTP credentials
include 'config.php';

// Connect to the FTP server using the stored credentials
$ftp_server = 'ftp.example.com';
$ftp_username = FTP_USERNAME;
$ftp_password = FTP_PASSWORD;

$ftp_connection = ftp_connect($ftp_server);
ftp_login($ftp_connection, $ftp_username, $ftp_password);

// Transfer files between servers
ftp_put($ftp_connection, 'remote_file.txt', 'local_file.txt', FTP_BINARY);

// Close the FTP connection
ftp_close($ftp_connection);