/** * Returns an object that is a child of the FTPClient class or null on failure. */ public static function initializeFTP() { if (self::$ftp === null && Config::get('base.ftp.enabled') == true) { self::$ftp = FTPClient::getObject(); $data = Config::get('base.ftp'); if (self::$ftp !== null && self::$ftp->setServer($data['host'], $data['port']) !== true) { self::$debug->addText('Could not set ftp server to ...'); self::$ftp = null; } if (self::$ftp !== null && self::$ftp->connect() !== true) { self::$debug->addText('Could not connect to ftp server'); self::$ftp->quit(); self::$ftp = null; } if (self::$ftp !== null && self::$ftp->login($data['username'], $data['password']) !== true) { self::$debug->addText('Could not login on ftp server with user data ...'); self::$ftp->quit(); self::$ftp = null; } if (self::$ftp !== null && self::$ftp->chdir($data['directory']) !== true) { self::$debug->addText('Could not change directory on ftp server to ...'); self::$ftp->quit(); self::$ftp = null; } } return self::$ftp; }
<?php 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; }