Link to home
Start Free TrialLog in
Avatar of brendan-amex
brendan-amex

asked on

PHP ftp_chmod Function

I'm trying to run a PHP script that will change the permissions on a file and am having troubles.

Below is what I have, but I'm afraid that I don't have enough knowledge to know why it's failing. It errors out each time I run it. I can FTP to this IP address no problem though. Even change permissions via my FTP client. I just need it to work here.

Thank you all!


<?php

$ftp_server="10.3.32.239";
$ftp_user_name="ftpuser";
$ftp_user_pass="password";
$file = '/uploads/test.txt';

 // set up basic connection
 $conn_id = ftp_connect($ftp_server);
// login with username and password
 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to chmod $file to 644
 if (ftp_chmod($conn_id, 0755, $file) !== false) {
 echo "$file chmoded successfully to 755\n";
} else {
 echo "could not chmod $file\n";
}
// close the connection
 ftp_close($conn_id);

 ?>
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I think you have to change to the directory where the file resides instead of trying to use a path to access it.  At least, that's what I had to do to get it to work.  See here: http://us2.php.net/manual/en/function.ftp-chdir.php
Avatar of brendan-amex
brendan-amex

ASKER

Well it allowed me to change directories, so that's good. But still it fails when trying to update the file with chmod

Dave, can you post the code that you got to work to compare to what I have?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I can't get it to work. I'm not sure why. I read that it needs to be php5 to run this command, but it definately is...
Did you change to $file = 'test.txt'; and put the directory in the ftp_chdir($conn_id, "/uploads") part?  When you are using an FTP program, you can only change files in the current directory.  You can't enter a path and do it that way in any FTP program I have.
I made sure of all that, I did a chdir to where the file is and it still doesn't work. The whole reason I was trying it in PHP is because an ubuntu issue with 10.04 on new files. I setup a cron task to run that re permissions new files and it seems to work. It's really ghetto, but it works. Thanks for the help.