set_time_limit(0);
$debug = true;
// Login information
include 'ftp_login.php';
// Include the FTP class
include 'ftp_class.php';
// Create the FTP object
$ftpObj = new FTPClient();
// Connect
if ($ftpObj->connect(FTP_HOST, FTP_USER, FTP_PASS)) {
    $File = "logfile_" . date('Ymd') . ".txt";
    $handle = fopen($File, 'a');
    //fwrite($Handle, $Data);
    $starttime = "\n===============start time of script " . date("l F d, Y, h:i A") . "===================";
    $ftpObj->writeLog($handle, $starttime);
    //$today = date('Ymd',strtotime("200 minutes")); // date format for folder YYYYMMDD i.e. 20110617
    $today = date('Ymd');
    $yesterday = date('Ymd');
    // previous date YYYYMMDD i.e. 20110617
    $h = date('H');
    //$h = date('H',strtotime("270 minutes"));
    if ($h == "00" || $h == "01" || $h == "02" || $h == "03" || $h == "04" || $h == "05" || $h == "06" || $h == "07") {
        $hourwisedir = "08";
        $dir = $yesterday . "/" . $hourwisedir;
    }
    if ($h == "08" || $h == "09" || $h == "10" || $h == "11" || $h == "12" || $h == "13" || $h == "14" || $h == "15") {
        $hourwisedir = "16";
        $dir = $today . "/" . $hourwisedir;
    }
    if ($h == "16" || $h == "17" || $h == "18" || $h == "19" || $h == "20" || $h == "21" || $h == "22" || $h == "23") {