I am running a php script that is executed on a server when someone clicks a button. The script downloads the file from one server stores the file locally then uploads it to another server.
But the file keeps corrupting somewhere in the middle the end file that is uploaded is always a different size and gets corrupted.
Code Below:
<?php
//Download CSV Script
// connect and login to FTP and download zip
$ftp_server = "URL REDACTED";
$ftp_conn = ftp_connect($ftp_server, 21) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, "USER", "PASS");
// turn passive mode on
ftp_pasv($ftp_conn, true);
$local_file = "feed/establishmentexport.zip";
$server_file = "establishmentexport.zip";
// download server file
if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII))
{
echo "Successfully downloaded from X.<br />";
}
else
{
echo "Error downloading feed. Please reload and retry.<br />";
}
// close connection
ftp_close($ftp_conn);
//End of download.
//FTP UPLOAD SCRIPTS
//Uploading the FTP file EMEA
$ftp_server = "REDACTED";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, "USER", "PASS");
// turn passive mode on
ftp_pasv($ftp_conn, true);
$local_file_u = "feed/establishmentexport.zip";
$server_file_u = "custom/establishmentexport.zip";
// upload file
if (ftp_put($ftp_conn, $server_file_u, $local_file_u, FTP_ASCII))
{
echo "Successfully uploaded to EMEA custom folder.<br />";
}
else
{
echo "Error uploading to EMEA custom folder.<br />";
}
// close connection
ftp_close($ftp_conn);
//End of Uploading the FTP file
?>