this is the script I created but PHP eventually times out
<?php
//Include PHP Mailer Class
require("class.phpmailer.php");
$LogDateTime = date("Y-m-d H:i:s");
$date = date("Y-m-d");
$date = date("Y-m-d");
$ftp_server = "FTP_Address";
$ftp_user_name = "FTP_UserName";
$ftp_user_pass = "FTP_Password";
$local_file = './downloaded/CellUpload'.$date.'.xls';
$server_file = 'CellUpload'.$date.'.xls';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result))
{
$LogDateTime = date("Y-m-d H:i:s");
//write data to logfile
$handle = fopen("./logs/log.txt", "a");
fwrite($handle,""."$LogDateTime"." "."[FTP CONNECT ERROR]"." "."Failed To Connect To"." "."$ftp_server"."\r\n");
fclose($handle);
$LogDateTime = date("Y-m-d H:i:s");
//write data to logfile
$handle = fopen("./logs/log.txt", "a");
fwrite($handle,""."$LogDateTime"." "."[FTP SLEEP]"." "."Waiting 60 Seconds To Retry Connection To"." "."$ftp_server"."\r\n");
fclose($handle);
sleep(60);
header("Location:ftp_script2.php");
exit;
}
else
{
$LogDateTime = date("Y-m-d H:i:s");
//write data to logfile
$handle = fopen("./logs/log.txt", "a");
fwrite($handle,"\r\n"."$LogDateTime"." "."[FTP CONNECTED]"." "."Connect Successfully To"." "."$ftp_server"."\r\n");
fclose($handle);
}
// Change The Directory
if (ftp_chdir($conn_id, "/public_html/reports/exports"))
{
$LogDateTime = date("Y-m-d H:i:s");
//write data to logfile
$handle = fopen("./logs/log.txt", "a");
fwrite($handle,""."$LogDateTime"." "."[FTP CHANGED DIRECTORY]"." "."Current Directory Is Now:"."(./public_html/reports/exports)"."\r\n");
fclose($handle);
}
else
{
$LogDateTime = date("Y-m-d H:i:s");
//write data to logfile
$handle = fopen("./logs/log.txt", "a");
fwrite($handle,"\r\n"."$LogDateTime"." "."[FTP CHANGED DIRECTORY ERROR]"."Failed To Change Directory To:"."(./public_html/reports/exports)"."\r\n");
fclose($handle);
exit;
}
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY))
{
$LogDateTime = date("Y-m-d H:i:s");
//write data to logfile
$handle = fopen("./logs/log.txt", "a");
fwrite($handle,""."$LogDateTime"." "."[FTP DOWNLOAD]"." "."File Successfully Downloaded To:"." "."($local_file)"."\r\n");
fclose($handle);
}
else
{
$LogDateTime = date("Y-m-d H:i:s");
//write data to logfile
$handle = fopen("./logs/log.txt", "a");
fwrite($handle,"".$LogDateTime." "."[FTP DOWNLOAD ERROR]"." "."Failed To Download File:"." "."($local_file)"."\r\n");
fclose($handle);
exit;
}
// close the FTP stream
ftp_close($conn_id);