Solved

FTP in PHP generating failed to open stream: Permission denied

Posted on 2009-05-12
4
2,335 Views
Last Modified: 2013-11-29

I have a working script on an existing web server Linux (FC7) that I'm now moving to a brand new sever just installed with FC10 and Apache.

The script attempts an FTP connect to copy files locally but is failing with a "failed to open stream: Permission denied".

All the directories have 777 permissions. Safe_mode is off via PHP_info. Since this a brand new install, I'm assuming something is set by default that I have to change (I've had to change a couple of things with setsebool so far to allow remote MySQL connections, etc, so maybe there's another switch affecting FTP that I'm unaware of.)


Log:
[Tue May 12 12:08:27 2009] [error] [client 192.168.55.41] TrafficCop2 for MPG
[Tue May 12 12:08:28 2009] [error] [client 192.168.55.41] PHP Warning:  ftp_get(/home/cer/mpg/3/current/2376.mpg) [<a href='function.ftp-get'>function.ftp-get</a>]: failed to open stream: Permission denied in /home/cer/public_html/ctrl/ScriptTrafficCop2.php on line 140
[Tue May 12 12:08:28 2009] [error] [client 192.168.55.41] PHP Warning:  ftp_get() [<a href='function.ftp-get'>function.ftp-get</a>]: Error opening /home/cer/mpg/3/current/2376.mpg in /home/cer/public_html/ctrl/ScriptTrafficCop2.php on line 140
 
php_info
safe_mode	Off	Off
safe_mode_exec_dir	no value	no value
safe_mode_gid	Off	Off
safe_mode_include_dir	no value	no value
 
 
Script:
error_log("TrafficCop2 for MPG");
 
$ftp_user_name = "me"; // Username
$ftp_user_pass = "mypassword";   // Password
$conn_id=ftp_connect("192.168.55.41");
 
//loginwithusernameandpassword
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
 
 
//checkconnection
if((!$conn_id)||(!$login_result)){
	growl('FTP connection failed on ScriptTrafficCop.php');
	die("FTP connection has failed!");
}
 
ftp_chdir($conn_id, "/Volumes/Storage/Channel Finished MOVs/listings/quicktime files/mpg");
 
	
$local_file  = "/home/cer/mpg/3/current/".$property['propertyid'].".mpg";
$server_file="/Volumes/Storage/Channel Finished MOVs/listings/quicktime files/mpg/".$property['propertyid'].".mpg";
if (file_exists($local_file)) unlink($local_file);
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY))
  growl($property['propertyid'].' mpg current copied');
else
  die($property['propertyid']." failed");

Open in new window

0
Comment
Question by:ktwdallas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:crash36936
ID: 24369616
I can't find any problem with the code.  Have you tried doing the FTP transfer manually?  Can you try it as the httpd/php user?
0
 

Author Comment

by:ktwdallas
ID: 24369702
If I ssh in as the cer user (the owner of the folder I'm trying to use), I can ftp to the machine and grab the file. I'm not sure I know how to start an ftp session as the apache or php user.
0
 
LVL 2

Expert Comment

by:crash36936
ID: 24370262
Well, If you have root access, you can `su <apache user>` (will likely need root password) and then try the same ftp command.  Apache (httpd) on linux often runs as `nobody` or `www`.  The username should be set in httpd.conf.

I'm sorry, this is a bit of trial an error.  Maybe someone else will have a more inspired idea.
0
 

Accepted Solution

by:
ktwdallas earned 0 total points
ID: 24370351
One of our local tech guys pointed out the problem. Actually it turns out that it's the new SElinux security addons that are new in FC10 that were causing the problem. I just disabled that and it all works now.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question