Ok, my hosting company tells me that they do not support zip functions, and I will have to use gzip to extract files from a .zip
Can the following script be changed to do this? I have no idea how to use gzip!
<?
define ( 'LOG_FILE', 'log.txt' ); // log file that records the complete process
define ( 'FTP_USER', xxxx' ); // ftp login username
define ( 'FTP_PASS', 'xxxx' ); // ftp login password
define ( 'FTP_HOST', 'xxxx' ); // ftp server name
define ( 'SAVE_PATH', '/xxxx/' ); // inlude the trailing '/'
$get_file = 'DailyData_CATisRES.zip'; // path and name of file on the FTP server (download file)
$new_file = SAVE_PATH . 'DailyData_CATisRES.zip'; // the local temp zip file name and path... (save file)
// end configure
$files = array ();
log_file ( 'SCRIPT (START): New database dump process started', 1 );
$io = ftp_connect ( FTP_HOST ) or log_file ( 'FTP CONNECT: connection error, ' . FTP_HOST, 0 );
log_file ( 'FTP (CONNECT): connection to ' . FTP_HOST . ' returned true', 1 );
if ( ( $lu = @ftp_login ( $io, FTP_USER, FTP_PASS ) ) !== false )
{
log_file ( 'FTP (LOGIN): login to ' . FTP_HOST . ' returned true', 1 );
$lf = fopen ( $new_file, 'wb' ) or log_file ( 'FILE ERROR: can not create temp file, ' . $new_file, 0 );
ftp_pasv($io, true) or log_file ( 'FTP PASV: Unable to set passive mode.', 0 );
if ( ftp_fget ( $io, $lf, $get_file, FTP_BINARY, 0 ) !== false )
{
log_file ( 'FTP (GET): get download file ' . $get_file . ' returned true', 1 );
fclose ( $lf );
log_file ( 'FILE (SAVE): saved down load file ' . $get_file . ' to ' . $new_file, 1 );
$zf = zip_open ( $new_file ) or log_file ( 'FILE ERROR: can not open to unzip, ' . $new_file, 0 );
if ( $zf )
{
while ( $zs = zip_read ( $zf ) )
{
if ( zip_entry_open ( $zf, $zs, 'rb' ) !== false )
{
$zo = zip_entry_read ( $zs, zip_entry_filesize ( $zs ) );
$fn = zip_entry_name ( $zs );
$fs = fopen ( SAVE_PATH . $fn, 'wb' );
fputs ( $fs, $zo );
fclose ( $fs );
$files[$fn] = SAVE_PATH . $fn;
}
}
zip_close ( $zf );
log_file ( 'FILE (UNZIP): process download file, ' . $new_file . ' returned true', 1 );
unlink ( $new_file );
}
else
{
log_file ( 'FILE ERROR: can not open or read ' . $new_file . ' (check permissions)', 0 );
}
}
else
{
log_file ( 'FILE ERROR: can not download ' . $get_file . ' from ' . FTP_HOST . ' (check path)', 0 );
}
ftp_close ( $io );
}
else
{
log_file ( 'FTP ERROR: user not allowed access on ' . FTP_HOST, 0 );
}
log_file ( 'SCRIPT (END): New database dump process finished, exiting...', 2 );
print "Scipt Seemed to Have Work";
function log_file ( $data, $type )
{
$time = date ( 'r', time () );
$fo = fopen ( LOG_FILE, 'a' );
fputs ( $fo, $time . ', ' . $data . "\r\n" );
if ( $type == 2 )
{
fputs ( $fo, str_repeat ( '-', 72 ) . "\r\n\r\n" );
}
fclose ( $fo );
if ( $type == 1 )
{
return;
}
exit ();
}
?>
Start Free Trial