I have a PHP script that I pass in the name of a file, it pushes the file to another computer, copies the file to an archive directory and unlinks the file. It works fine. I have 2 programs that call the script both call it the same way, either I can call it with a (to post 1 file at a time) or rapid fire with cURL (to post all). Program A works fine either way but program B if I call it with the it works fine, if I call it with cURL it won’t unlink and it gives me a Permission denied error. How do I fix this?
Sounds a whole lot like the way most script kiddie attacks work .... If would help to post the code and the error message you're receiving.
If it works for program a it should work for program …zCode for driver programs if ($Posting == 'ON') { if ($postAll == "Post All") { $ch = curl_init(); $cURL = 'http://localhost/ftp/PostERAs.php'; curl_setopt($ch, CURLOPT_URL, $cURL); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // Ask cURL to return the contents in a variable instead of simply echoing them to // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt($ch, CURLOPT_POSTFIELDS, 'FacilityNumber='.$FacilityNumber.'&selected='.$file.'&send_dir='.$dir.'&submitted=submitted'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); // Execute the cURL session $contents = curl_exec ($ch); echo $contents; // In this case it returns undesirable information echo $cURL; // for testing echo ' '.$dir; // Close cURL session curl_close ($ch); } else { echo ''; echo ' '; echo 'Post at '.$dst_dir.''.$FacilityNumber. '/'.$mth.'/'.$file.''; echo ''; echo ''; echo ''; echo '[HR][/HR]'; echo ''; } }Code form posting program if (copy($send_file, $newfile)) { unlink($send_file); // Delete work file } else echo 'copy '.$send_file.' to '.$newfile.' did not work ';Error message from when called form 1 of the driver with cURL onlyWarning: unlink(C:\X12\Reports\Claim_Report_280302044.TXT) [function.unlink]: Permission denied in C:\WebServ\wwwroot\htdocs\ftp\PostERAs.php on line 68
If it works for program a it should work for program …z Code for driver programs if ($Posting == 'ON') { if ($postAll == "Post All") { $ch = curl_init(); $cURL = 'http://localhost/ftp/PostERAs.php'; curl_setopt($ch, CURLOPT_URL, $cURL); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // Ask cURL to return the contents in a variable instead of simply echoing them to // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt($ch, CURLOPT_POSTFIELDS, 'FacilityNumber='.$FacilityNumber.'&selected='.$file.'&send_dir='.$dir.'&submitted=submitted'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); // Execute the cURL session $contents = curl_exec ($ch); echo $contents; // In this case it returns undesirable information echo $cURL; // for testing echo ' '.$dir; // for testing // Close cURL session curl_close ($ch); } else { echo 'form enctype="multipart/form-data" action="./../../ftp/PostERAs.php" method="post"'; echo ' input type="submit" value="Post file" name="Post" /'; echo 'Post at font color=green'.$dst_dir.'/font font color=orange'.$FacilityNumber. '/font font color=green//font font color=Fuchsia'.$mth.'/font font color=green/'.$file.'/font'; echo 'input type="hidden" name="FacilityNumber" value="'.$FacilityNumber.'" /'; echo ‘input type="hidden" name="selected" value="'.$file.'" /'; echo 'input type="hidden" name="send_dir" value="'.$dir.'" /'; echo 'hr'; echo '/form'; } } Code form posting program if (copy($send_file, $newfile)) { unlink($send_file); // Delete work file } else echo 'copy '.$send_file.' to '.$newfile.' did not work '; Error message from when called form 1 of the driver with cURL only Warning: unlink(C:\X12\Reports\Claim_Report_280302044.TXT) [function.unlink]: Permission denied in C:\WebServ\wwwroot\htdocs\ftp\PostERAs.php on line 68 Sorry about the HTML coding it won’t let me put a right and left arrow
It's not really possible to effectively troubleshoot this from the code provided. Also, I am not a Windows server admin but this might get you pointed in the right direction: I believe the user running curl must have IUSR rights on the folder where the file is being unlinked.