Well, i did open a ticket and the permissions were changed from '99' back to user permissions. However, I dont think that is my issue here. At least, only part of my issue here. I think ive isolated it to be the FTP retreival.
Let me explain furthur..mabye some PHP guru's can see an issue with what Im doing.
Im trying to FTP a log file from a remote server to the local webserver via PHP. In order to do this I need to have a file on the webserver to download it to. Now, in code, if the file doesnt exist locally I use the fopen() function in PHP to create the file so it has somewhere to write to. Ive noticed when I do this that the ownership of the file I have created is set to '99' (nobody) because thats just the way it is when u create via PHP script.
Everything to this point is fine and dandy. The FTP grabs the file remotley and it is downloaded to the webserver no problem...here is the results i get...
So, the file (even with permissions of 99) holds the FTP data i gathered from the remote file. My parser can read from it and no issues. The new file on my webserver is called '2.log' and it has the appropriate file size with. The problem becomes when I try to resume the FTP from the previous position.
Here is the function that I use to FTP the file and do all the work. Ive tried doing this multiple ways with multiple approaches and they all fail on file resume. I dont think its a file permissions error at this point because even when i manually FTP up a '2.log' file with non-nobody permissions and try to resume, I still get an error on ftp_get().
>function ftpConnect($ip, $user, $pass, $path, $file, $dest)
{
//check validity
$i = 0;
if(file_exists($dest))
{ //check for the current file
$local_file_size = filesize($dest);
if($local_file_size)
rw("\n$dest exists @ size: $local_file_size");
}
else
{ //try creating the file...
rw("\nTrying to create new local log file".$dest);
if ($fileconn = @fopen($dest, 'w'))
{ chmod($dest, 0666);
fputs($fileconn, "");
fclose($fileconn);
}
else
trigger_error("Unable to create a local file", E_USER_ERROR);
//clear cache
clearstatcache();
//now check the file again
if(file_exists($dest))
{ //now lets get the file size!
rw("\n$dest was created sucessfully");
$local_file_size = filesize($dest); //we know its there dont care if its 0
}
else
trigger_error("Unable to create a local file", E_USER_ERROR);
}
//clear cache
clearstatcache();
//disable script timeout
set_time_limit(0);
// set up basic connection
$conn_id = ftp_connect($ip);
// login with username and password
$login_result = ftp_login($conn_id, $user, $pass);
// check connection
if ((!$conn_id) || (!$login_result))
trigger_error("FTP Connection has failed on $ip for user $user", E_USER_ERROR);
else
trigger_error("Connected to $ip, for user $user", E_USER_NOTICE);
// Get remote filesize
if(ftp_chdir($conn_id, $path))
{ //size of file
$remote_file_size = ftp_size($conn_id, $file);
//check validity
if($remote_file_size)
rw("\n$path$file exists @ size: $remote_file_size");
//check the remotesize
if ( $remote_file_size == -1 || $remote_file_size < $local_file_size )
{ rw("\nRemote filesize of $remote_file_size < $local_file_size, log file reset!");
// Reset logfilesize
$local_file_size = 0;
}
//clear cache
clearstatcache();
rw("\nDest: $dest File: $file LocalSize: $local_file_size");
// try to download $server_file and save to $local_file
if(is_readable($dest))
{ //can we read the file?
if(ftp_get($conn_id, $dest, $path.$file, FTP_BINARY, $local_file_size))
rw("\nDownload Complete");
else
rw("\nError loading file");
}
else
trigger_error("Unable to read from local file", E_USER_ERROR);
}
else
trigger_error("Error changing to directory $path", E_USER_ERROR);
// close the FTP stream and doc stream
ftp_close($conn_id);
//reenable script time out
set_time_limit(30);
The most annoying part about this is that the file will be deleted once it fails. So, I have to redownload a huge log file in the event it fails. Me no likey.
Suggestions?