FTP Automation PHP Code

Basicly this is a php page that can be ran from either a browser or as a cron job. The agftp.php page creates the objects, sets applicable variables, and calls the required functions. Each function is fully contained and functional on it's own. This allows you to comment out functions that are not required as to create an individule workflow for each client. The full workflow is as follows...

Connects to the ftp server.
Gets the directory listing and determines if there are any new files.
Gets the new files.
Archives the newly downloaded files on the ftp server.
Moves the newly downloaded files to their final location on the network.
Looks for new files to push to the ftp server.
Pushes those files to the server.
Archives the newly pushed files.
Closes the FTP connection.
Notifies via email of new files or any errors.

Functions also exist to output to log files in html, windows .txt, and unix .txt files, get the initial default file listing, print array diag info, and to compress and archive log files.

FYI, This is a work in progress and subject to major changes....

This is the main page that calls the functions......

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
agftp.php>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

[code]
ftp_user_name = "username"; //FTP server username
$TEST->ftp_user_pass = "password"; //FTP server password
$TEST->ftp_dir = NULL; //Active directory on FTP server
$TEST->ftp_server = "ftp.somewhere.com"; //FTP Server address
$TEST->passivemode; //To turn passive mode on or off
$TEST->list_default_file; //Name of file containing the default directory listing
$TEST->movefileto = "/mnt/agdevftp/CLIENTS/mcs/"; //Directory to move files to after download is complete on the network
$TEST->archdir = "."; //Directory to move files to after download is complete on the FTP server
$TEST->push_from_dir = "/home/ftpusers/ftpalc/toclient/"; //Directory to push files from network to the FTP server
$TEST->push_to_dir = "IN"; //Directory to push files to on the FTP server
$TEST->push_arch_dir = "archive/"; //Directory pushed files are archived to this network directory
$TEST->output_type = "web"; //Determines which type of log is generated, log format or html format
$TEST->email_to1 = "will@aghealth123.com"; //Email to address
$TEST->email_to2 = "jonn@aghealth123.com"; //Email to address
$TEST->email_to3 = "jonn@aghealth123.com"; //Email to address
$TEST->email_to4 = "jonn@aghealth123.com"; //Email to address
$TEST->email_to5 = "jonn@aghealth123.com"; //Email to address
$TEST->email_subject = "MCS New File Notification"; //Email subject default
$TEST->email_from = "MCSAutomation@aghealth123.com"; //Email from default
$TEST->email_body = "Please view the attached logfile."; //Email body default
$TEST->email_pri = 4; //Email priority default
$TEST->logfile = "log/logfile"; //Log file name minus timestamp
$TEST->client = "ALC"; //Client Name

$TEST->agoutput("#####################################################################################");
$TEST->agoutput("TEST FTP PROCESS");
$TEST->agoutput("#####################################################################################");
$TEST->agftpconnect(); //Connect to the FTP Server
$TEST->agftpgetinitdefaultlist(); //Get the default initial list
$TEST->agftpgetnewlist(); //Get a list of new files
$TEST->agftpgetfiles(); //Get new files that are on the new file list
$TEST->agftparchfiles(); //Archive files on the FTP server. Rename/Move
$TEST->agftpmovefiles(); //Moves the downloaded files to their final location on the network
$TEST->agpushlist(); //Gathers a list of files to PUSH to the FTP Server
$TEST->agpushtoftp(); //Uploads the files on the push_dir_list to the FTP server
$TEST->agpusharchfiles(); //Archive files on the network server. Rename/Move
$TEST->agftpclose(); //Close the connection to the FTP Server
$TEST->agmailnotify(); //Emails notification of new file
$TEST->printinfo(); //Prints array info for diag purposes
*/

///////////////////////// MCS Account Setup /////////////////////////
$MCS = new AGFTP;
$MCS->ftp_user_name = "username"; //FTP server username
$MCS->ftp_user_pass = "password"; //FTP server password
$MCS->ftp_dir = NULL; //Active directory on FTP server
$MCS->ftp_server = "ftp.somewhere.com"; //FTP Server address
// $MCS->passivemode; //To turn passive mode on or off
// $MCS->list_default_file; //Name of file containing the default directory listing
$MCS->movefileto = "/mnt/agdevftp/CLIENTS/mcs/"; //Directory to move files to after download is complete on the network
$MCS->archdir = "."; //Directory to move files to after download is complete on the FTP server
// $MCS->push_from_dir = "/home/ftpusers/ftpalc/toclient/"; //Directory to push files from network to the FTP server
$MCS->push_to_dir = "IN"; //Directory to push files to on the FTP server
$MCS->output_type = "web"; //Determines which type of log is generated, log format or html format
$MCS->email_to1 = "will@aghealth123.com"; //Email to address
$MCS->email_to2 = "jonn@aghealth123.com"; //Email to address
$MCS->email_to3 = "scottv@aghealth123.com"; //Email to address
// $MCS->email_to4 = "jonn@aghealth123.com"; //Email to address
// $MCS->email_to5 = "jonn@aghealth123.com"; //Email to address
$MCS->email_subject = "MCS New File Notification"; //Email subject default
$MCS->email_from = "MCSAutomation@aghealth123.com"; //Email from default
$MCS->email_body = "Please view the attached logfile."; //Email body default
// $MCS->email_pri = 4; //Email priority default
$MCS->logfile = "log/mcslogfile"; //Log file name minus timestamp
$MCS->client = "MCS"; //Client Name

$MCS->agoutput("#####################################################################################");
$MCS->agoutput("MCS FTP PROCESS");
$MCS->agoutput("#####################################################################################");
$MCS->agftpconnect(); //Connect to the FTP Server
// $MCS->agftpgetinitdefaultlist(); //Get the default initial list
$MCS->agftpgetnewlist(); //Get a list of new files
$MCS->agftpgetfiles(); //Get new files that are on the new file list
// $MCS->agftparchfiles(); //Archive files on the FTP server. Rename/Move
$MCS->agftpmovefiles(); //Moves the downloaded files to their final location on the network
// $MCS->agpushlist(); //Gathers a list of files to PUSH to the FTP Server
// $MCS->agpushtoftp(); //Uploads the files on the push_dir_list to the FTP server
$MCS->agpusharchfiles(); //Archive files on the network server. Rename/Move
$MCS->agftpclose(); //Close the connection to the FTP Server
$MCS->agmailnotify(); //Emails notification of new file
$MCS->printinfo(); //Prints array info for diag purposes

///////////////////////// ALC Account Setup /////////////////////////
$ALC = new AGFTP;
$ALC->ftp_user_name = "username"; //FTP server username
$ALC->ftp_user_pass = "password"; //FTP server password
$ALC->ftp_dir = "OUT"; //Active directory on FTP server
$ALC->ftp_server = "ftp.somewhere.com"; //FTP Server address
// $ALC->passivemode; //To turn passive mode on or off
// $ALC->list_default_file; //Name of file containing the default directory listing
$ALC->movefileto = "/mnt/ftpalc/fromclient/"; //Directory to move files to after download is complete on the network
$ALC->archdir = "Archive"; //Directory to move files to after download is complete on the FTP server
$ALC->push_from_dir = "/mnt/ftpalc/toclient/"; //Directory to push files from network to the FTP server
$ALC->push_to_dir = "IN"; //Directory to push files to on the FTP server
$ALC->output_type = "web"; //Determines which type of log is generated, log format or html format
$ALC->email_to1 = "will@aghealth123.com"; //Email to address
$ALC->email_to2 = "jonn@aghealth123.com"; //Email to address
$ALC->email_to3 = "scottv@aghealth123.com"; //Email to address
// $ALC->email_to4 = "jonn@aghealth123.com"; //Email to address
// $ALC->email_to5 = "jonn@aghealth123.com"; //Email to address
$ALC->email_subject = "ALC New File Notification"; //Email subject default
$ALC->email_from = "ALCAutomation@aghealth123.com"; //Email from default
$ALC->email_body = "Please view the attached logfile."; //Email body default
// $ALC->email_pri = 4; //Email priority default
$ALC->logfile = "log/alclogfile"; //Log file name minus timestamp
$ALC->client = "ALC"; //Client Name

$ALC->agoutput("#####################################################################################");
$ALC->agoutput("ALC FTP PROCESS");
$ALC->agoutput("#####################################################################################");
$ALC->agftpconnect(); //Connect to the FTP Server
// $ALC->agftpgetinitdefaultlist(); //Get the default initial list
$ALC->agftpgetnewlist(); //Get a list of new files
$ALC->agftpgetfiles(); //Get new files that are on the new file list
$ALC->agftparchfiles("alc"); //Archive files on the FTP server. Rename/Move
$ALC->agftpmovefiles(); //Moves the downloaded files to their final location on the network
$ALC->agpushlist(); //Gathers a list of files to PUSH to the FTP Server
$ALC->agpushtoftp(); //Uploads the files on the push_dir_list to the FTP server
$ALC->agpusharchfiles(); //Archive files on the network server. Rename/Move
$ALC->agftpclose(); //Close the connection to the FTP Server
$ALC->agmailnotify(); //Emails notification of new file
$ALC->printinfo(); //Prints array info for diag purposes

?>[/code]

this is the included function code used by the main program.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ftpfunction.php >>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

[code]
output_type == "web") {
$filename = $this->logfile . date("YmdHis") . ".html";
} else {
$filename = $this->logfile . date("YmdHis") . ".txt";
}

if ($this->logfile_whole) {
$filename = $this->logfile_whole;
} else {
$this->logfile_whole = $filename;
}

if (!$handle = fopen($filename, 'a')) {
$this->errorflag = true;
echo "Cannot open file ($filename).";
$this->email_body = $this->email_body . " Error: Cannot open file ($filename).";
return;
}
if ($this->output_type == "log") {
if ($nobreak) {
if (fwrite($handle, $output_string) === false) {
$this->errorflag = true;
echo "Cannot write to file ($filename).";
$this->email_body = $this->email_body . " Error: Cannot write to file ($filename).";
return;
}
printf("%s", $output_string);
} else {
if (fwrite($handle, $output_string . "\n") === false) {
$this->errorflag = true;
echo "Cannot write to file ($filename).";
$this->email_body = $this->email_body . " Error: Cannot write to file ($filename).";
return;
}
printf("%s \n", $output_string);
}
}
if ($this->output_type == "web") {
if ($nobreak) {
if (fwrite($handle, $output_string) === false) {
$this->errorflag = true;
echo "Cannot write to file ($filename).";
$this->email_body = $this->email_body . " Error: Cannot write to file ($filename).";
return;
}
printf("%s", $output_string);
} else {
if (fwrite($handle, $output_string . "
") === false) {
$this->errorflag = true;
echo "Cannot write to file ($filename).";
$this->email_body = $this->email_body . " Error: Cannot write to file ($filename).";
return;
}
printf("%s
", $output_string);
}
}
if ($this->output_type != "web" AND $this->output_type != "log") {
$this->errorflag = true;
echo "OUTPUT TYPE UNKNOWN";
$this->email_body = $this->email_body . " Error: Log file output type unknown.";
return;
}

fclose($handle);
}

//*********************************************************************************************************************
// AGFTPCONNECT Connects to the FTP server
//*********************************************************************************************************************
function agftpconnect() {
$this->agoutput("*************agftpconnect fuction started***************");
if (($this->conn_id = ftp_connect($this->ftp_server)) == false) {
$this->errorflag = true;
$this->abort = true;
$this->email_body = $this->email_body . " Error: Failed to connect to FTP server.";
}
if (($this->login_result = ftp_login($this->conn_id, $this->ftp_user_name, $this->ftp_user_pass)) == false){
$this->errorflag = true;
$this->abort = true;
$this->email_body = $this->email_body . " Error: Failed to login to FTP server.";
}
if ((!$this->conn_id) || (!$this->login_result)) {
$this->errorflag = true;
$this->abort = true;
$this->agoutput("FTP connection has failed!");
$this->agoutput("Attempted to connect to $this->ftp_server for user $this->ftp_user_name.");
$this->email_body = $this->email_body . " Error: Attempted to connect to $this->ftp_server for user $this->ftp_user_name.";
return;
} else {
$this->agoutput("Connected to $this->ftp_server, for user $this->ftp_user_name.");
}
if ($this->passivemode == "true") {
if (ftp_pasv($this->conn_id, true)) {
$this->agoutput("Passive set to true.");
} else {
$this->errorflag = true;
$this->abort = true;
$this->agoutput("Passive failed to set to true.");
$this->email_body = $this->email_body . " Error: Passive failed to set to true.";
}
}
if ($this->passivemode == "false") {
if (ftp_pasv($this->conn_id, "false")) {
$this->agoutput("Passive set to false.");
} else {
$this->errorflag = true;
$this->abort = true;
$this->agoutput("Passive failed to set to false.");
$this->email_body = $this->email_body . " Error: Passive failed to set to false.";
}
}
$this->agoutput();
return $this->login_result;
}

//*********************************************************************************************************************
// AGFTPGETNEWLIST Retreives dir list from server, compares to default list and returns list of new files.
//*********************************************************************************************************************
function agftpgetnewlist(){
$this->agoutput("*************agftpgetnewlist fuction started************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
if ($this->ftp_dir){
if (ftp_chdir($this->conn_id, $this->ftp_dir)){
$this->agoutput("Changed dir to $this->ftp_dir.");
} else {
$this->errorflag = true;
$this->agoutput("Failed to change to dir $this->ftp_dir.");
$this->email_body = $this->email_body . " Error: Failed to change to dir $this->ftp_dir.";
return;
}
}
if (!$this->current_dir = ftp_nlist($this->conn_id, "")) {
$this->current_dir = NULL;
$this->newfile = NULL;
$this->agoutput("NO new files found.");
} else {
$this->agoutput("Current directory listing retrieved.");
}

// gets default listing into array
if (!$this->list_default_file) $this->list_default_file=$this->ftp_server . ".txt";
$this->opened_default_file=file($this->list_default_file);
$this->default_file_lines = count($this->opened_default_file);
$this->arraycount = 0;
while ($i = each($this->opened_default_file)){
$this->default_file_array[$this->arraycount] = $i['value'];
//strips leading and trailing spaces out
$this->default_file_array[$this->arraycount] = trim($this->default_file_array[$this->arraycount]);
$this->arraycount++;
}

// check the array differeces
if ($this->current_dir) {
$this->result = array_diff($this->current_dir, $this->default_file_array);
}
if (count($this->result) != 0) {
$this->email_body = $this->email_body . " New inbound files found.";
$this->newfile = true;
}
// $array = array();
// $array[0] = "\n";
// $result = array_diff($result,$array);
$this->agoutput();

}

////Error check improvement stop here

//*********************************************************************************************************************
// AGFTPGETFILES Downloads the files on the new file list
//*********************************************************************************************************************
function agftpgetfiles(){
$this->agoutput("*************agftpgetfiles fuction started**************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
if (!$this->newfile) {
$this->agoutput("NO new files found.");
$this->agoutput();
return;
}
reset($this->result);
foreach($this->result as $this->file) {
$this->agoutput("This is the file attempting to get... $this->file.");
if (ftp_get($this->conn_id, $this->file, $this->file, FTP_BINARY)) {
$this->agoutput("Successfully written to $this->file.");
} else {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem with $this->file.");
}
}
$this->agoutput();
}

//*********************************************************************************************************************
// PRINTINFO Prints array info for diag purposes.
//*********************************************************************************************************************
function printinfo(){
$this->agoutput("*************printinfo fuction started******************");
$this->agoutput("Current Dir .............", true);
var_dump($this->current_dir);
$this->agoutput();
$this->agoutput("Default Dir .............", true);
var_dump($this->default_file_array);
$this->agoutput();
$this->agoutput("Differences Dir .........", true);
var_dump($this->result);
$this->agoutput();
$this->agoutput("Push Dir ................", true);
var_dump($this->push_dir_list);
$this->agoutput();
}

//*********************************************************************************************************************
// AGFTPCLOSE Closes the FTP connection
//*********************************************************************************************************************
function agftpclose(){
$this->agoutput("*************agftpclose fuction started*****************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
ftp_close($this->conn_id);
$this->agoutput("FTP Connection closed.");
$this->agoutput();
}

//*********************************************************************************************************************
// AGFTPMOVEFILES Moves the downloaded files to their final location on the network.
//*********************************************************************************************************************
function agftpmovefiles() {
$this->agoutput("*************agftpmovefiles fuction started*************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
if ($this->newfile) {
reset($this->result);
foreach($this->result as $this->file) {
$this->agoutput(" This is the file attempting to move... $this->file.");
if (rename($this->file, $this->movefileto . $this->file)) {
$this->agoutput("Successfully moved to $this->movefileto.");
} else {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem with $this->file.");
}
if ($this->movfileto2) {
if (rename($this->file, $this->movfileto2 . $this->file)) {
$this->agoutput("Successfully moved to $this->movefileto.");
} else {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem with $this->file.");
}
}
}
} else {
$this->agoutput("NO new files to move.");
}
$this->agoutput();
}

//*********************************************************************************************************************
// AGFTPGETINITDEFAULTLIST Retrieves the inital directory listing to use as default
//*********************************************************************************************************************
function agftpgetinitdefaultlist(){
$this->agoutput("*************agftpgetinitdefaultlist fuction started********");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
if ($this->ftp_dir){
if (ftp_chdir($this->conn_id, $this->ftp_dir)){
$this->agoutput("Changed dir to $this->ftp_dir.");
} else {
$this->errorflag = true;
$this->agoutput("Failed to change to dir $this->ftp_dir.");
return;
}
}
// List current direcoty
$this->current_dir = ftp_nlist($this->conn_id, ".");
reset ($this->current_dir);
if (file_exists($this->ftp_server . ".txt")) {
unlink($this->ftp_server . ".txt");
$this->agoutput("Deleting file $this->ftp_server.txt.");
}

if (!$this->handle = fopen($this->ftp_server . ".txt", 'a')) {
$this->errorflag = true;
$this->agoutput("Cannot open file ($this->ftp_server.txt)");
return;
}
foreach($this->current_dir as $this->file) {
if (fwrite($this->handle, $this->file . "\n") === false) {
$this->errorflag = true;
$this->agoutput("Cannot write to file ($this->ftp_server.txt)");
return;
}
$this->agoutput("Success, wrote ($this->file) to file ($this->ftp_server.txt) ");
}
fclose($this->handle);
$this->agoutput();
}

//*********************************************************************************************************************
// AGFTPARCHFILES Moves on the FTP server downloaded files to the FTP archive directory.
//*********************************************************************************************************************
function agftparchfiles($client = NULL) {

if ($client == "alc") {
$this->agoutput("*************agftparchfiles fuction started*************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
reset($this->result);
foreach($this->result as $this->file) {
$this->agoutput(" This is the file attempting to archive... $this->file.");
if (ftp_put($this->conn_id, $this->archdir . "/" . $this->file, $this->file, FTP_BINARY)) {
$this->agoutput("Successfully moved file $this->file to $this->archdir.");
if (ftp_delete($this->conn_id, $this->file)) {
$this->agoutput("Successfully deleted orginal file");
} else {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem archiving $this->file.");
}
} else {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem archiving $this->file.");
}
}
if(count($this->result) == 0) $this->agoutput("NO files were archived");
$this->agoutput();
} else {
$this->agoutput("*************agftparchfiles fuction started************");
reset($this->result);
foreach($this->result as $this->file) {
$this->agoutput(" This is the file attempting to archive... $this->file.");
if (ftp_rename($this->conn_id, $this->file, $this->archdir . $this->file)) {
$this->agoutput("Successfully moved file $this->file to $this->archdir.");
} else {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem archiving $this->file.");
}
}
if(count($this->result) == 0) $this->agoutput("NO files were archived");
$this->agoutput();
}
}

//*********************************************************************************************************************
// AGPUSHLIST Gathers a list of files to PUSH to the FTP Server.
//*********************************************************************************************************************
function agpushlist() {
$this->agoutput("*************agpushlist fuction started*****************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
if ($this->handle = opendir($this->push_from_dir)) {
$this->arraycount = 0;
while (false !== ($this->file = readdir($this->handle))) {
// if ($this->file !== "." && $this->file !== ".." && strrchr($this->file, ".") == ".pgp") {
if ($this->file !== "." && $this->file !== ".." && strcasecmp(strrchr($this->file, "."), ".pgp") == 0) {
$this->push_dir_list[$this->arraycount] = $this->file;
$this->newfile_push = true;
$this->email_body = $this->email_body . " NEW outbout files found.";
$this->arraycount++;
}
}
closedir($this->handle);

}
if (!$this->newfile_push) {
$this->agoutput("NO outbound files found.");
} else {
$this->agoutput("NEW outbound files found.");
}
$this->agoutput();
}

//*********************************************************************************************************************
// AGPUSHTOFTP Uploads the files on the push_dir_list to the FTP server.
//*********************************************************************************************************************
function agpushtoftp(){
$this->agoutput("*************agpushtoftp fuction started****************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
if (!$this->newfile_push) {
$this->agoutput("NO new files found.");
$this->agoutput();
return;
}

if ($this->push_to_dir){
echo "Current directory: " . ftp_pwd($this->conn_id) . "\n";
ftp_chdir($this->conn_id, "..");
if (ftp_chdir($this->conn_id, $this->push_to_dir)){
$this->agoutput("Changed dir to $this->push_to_dir.");
} else {
$this->errorflag = true;
$this->agoutput("Failed to change to dir $this->push_to_dir.");
return;
}
}

reset($this->push_dir_list);
foreach($this->push_dir_list as $this->file) {
$this->agoutput("This is the file attempting to push... $this->file.");
if (ftp_put($this->conn_id, $this->file, $this->push_from_dir . $this->file, FTP_BINARY)) {
$this->agoutput("Successfully pushed to $this->file.");
} else {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem with $this->file.");
}
}
$this->agoutput();

}

//*********************************************************************************************************************
// AGPUSHTARCHFILES Archive files on the network server. Rename/Move
//*********************************************************************************************************************
function agpusharchfiles(){
$this->agoutput("*************agpusharchfiles fuction started************");
if ($this->abort == true){
$this->agoutput("Function Aborted");
return;
}
if($this->newfile_push) {
reset($this->push_dir_list);
foreach($this->push_dir_list as $this->file) {
if(!rename($this->push_from_dir . $this->file, $this->push_from_dir . $this->push_arch_dir . $this->file)) {
$this->errorflag = true;
$this->agoutput("Oopps, There was a problem archiving $this->file.");
} else {
$this->agoutput("$this->file archived normally.");
}
}
} else {
$this->agoutput("NO files to archive.");
}
$this->agoutput();
return;
}

", $m->Get(), "







//*********************************************************************************************************************
// AGCOMPRESSLOGS Gathers a list of files to PUSH to the FTP Server.
//*********************************************************************************************************************
function agcompresslogs() {
$this->agoutput("*************agcompresslogs fuction started*****************");
if ($this->handle = opendir("log/")) {
$this->arraycount = 0;
while (false !== ($this->file = readdir($this->handle))) {
// if ($this->file !== "." && $this->file !== ".." && strrchr($this->file, ".") == ".pgp") {
if ($this->file !== "." && $this->file !== ".." && $this->file !== "archive") {
$this->logfile_list[$this->arraycount] = "log/" . $this->file;
$this->arraycount++;
}
}
closedir($this->handle);
}

include("tar.php");
$filename = "archive/archive" . date("YmdHis") . ".tar.gz";
$tar_object = new Archive_Tar($filename, true);
$tar_object->setErrorHandling(PEAR_ERROR_PRINT); // Optional error handling
$tar_object->createModify($this->logfile_list, "");
reset($this->logfile_list);
sleep(15);
foreach($this->logfile_list as $this->file) {
if(!unlink($this->file)) {
$this->agoutput("A problem was encountered attempting to delete $this->file.");
} else {
// $this->agoutput("$this->file archived normally.");
}
}

$this->agoutput("Logfile Dir ................", true);
var_dump($this->logfile_list);

$this->agoutput("Compress function complete.");
$this->agoutput();
}

}
?>
[/code]