duannai5858 2011-12-14 13:16
浏览 52
已采纳

ftp_site()不想更改文件夹上的CHMOD

I have a joomla page on which I want to install a few extensions. However due to the chmod permissions I am unable to upload and install the packages. Following the guide here I can see that in order for the plugins to be installed there are too many folders which permissions have to be changed.

For that I am creating a script which will iterate through each of the required folders and will change the permissions from 0775 to 0777.

<?php
// SET THE DESIRED CHMOD VALUE
if ($_GET['chmod']) { 
        $ftp_chmod = $_GET['chmod']; 
    } 
    else { 
        $ftp_chmod = "0755"; 
    }
echo "chmod=" . $ftp_chmod . '<br />';
echo getcwd() . '<br />';
$currdir = getcwd(); // get current directory

// ESTABLISH AN FTP LOGIN SESSION
$ftp_server='example.com';
$ftp_user='username';
$ftp_pass='*****';
$conn_id = ftp_connect("$ftp_server");

if ( ftp_login($conn_id, $ftp_user, $ftp_pass) ) {
    echo 'FTP CONNECTION IS SUCCESSFULL <br />';
}
else {
    echo 'BAD CREDENTIALS';
    exit();
}

// Define the folders for which the CHMODE will change the values
// There must be a leading space in front of the path in order for CHMOD to work
$folder_path = array(
    ' ' . $currdir . '/modules/',
    ' ' . $currdir . '/plugins/'
    ' ' . $currdir . '/tmp/',
    ' ' . $currdir . '/cache/'
);

echo '<br />';
foreach ( $folder_path as $key => $value )
{
    $path = trim($value); // The leading space must be trimed fo is_dir() function to work

    if ( is_dir($path) == true ) {

        echo $path . ' -- ' . '<span style="color: #00B200">OK</span><br />';
        echo 'CHMOD ' . $ftp_chmod . '  ' . $value . '<br />';

        if (ftp_site($conn_id, 'CHMOD ' . $ftp_chmod . $value)) {
            echo 'CHMOD ' . $ftp_chmod . ' IS <span style="color: #00B200">SUCCESSFULL</span><br /><br />';
        }
        else {
            echo '<span style="color: crimson">CHMOD FAILED!</span><br /><br />';
        }
    }
    else {
        echo $path . ' -- ' . '<span style="color: crimson"><b>NOT EXIST</b></span><br />';
    } // end if ( is_dir($path) == true ) else

} // end foreach ( $folder_path as $key => $value )

ftp_close($conn_id);
?>

Please note that the actual script is much larger due to the many folders that need to be changed. The folders shown in $folder_path = array() are just an example

When I execute the script on my server i get the folowind output:

chmod=0777
/var/www/example/data/www/example.com
FTP CONNECTION IS SUCCESSFULL 

/var/www/example/data/www/example.com/modules/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/modules/
CHMOD FAILED!

/var/www/example/data/www/example.com/plugins/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/plugins/
CHMOD FAILED!

/var/www/example/data/www/example.com/tmp/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/tmp/
CHMOD FAILED!

/var/www/example/data/www/example.com/cache/ -- OK
CHMOD 0777 /var/www/example/data/www/example.com/cache/
CHMOD FAILED!

DOES ANYONE HAVE ANY IDEA ON HOW TO CHANGE THE CHMOD VALUE ON SO MANY FOLDERS?


UPDATE:
I also have to mention that I have tried to change the CHMOD value on each folder individually via FTP client and it is successfull. The problem comes when i have to change them through the script. The same acc with root privilege access is used from the FTP client and the script to change the files!

  • 写回答

2条回答 默认 最新

  • dpvv37755 2011-12-15 14:30
    关注

    I have found a solution to the problem. What I did was a small modification to the foreach part of the script which made it work. Basically I just subtracted the required number of characters from the path returned from the getcwd() and that solved my problem.

    Here is the change that i did:

    ---- REST OF THE SCRIPT OMITED -----
    
    foreach ( $folder_path as $key => $value )
    {
        $path = trim($value); // The leading space must be trimed fo is_dis() function to work
    
        if ( is_dir($path) == true ) {
    
            $value_short = substr($value, 19); // <------------- Subtruct the required number od chars in order to create a relative path
    
            echo $path . ' -- ' . '<span style="color: #00B200">OK</span><br />';
            echo 'CHMOD ' . $ftp_chmod . '  ' . $value_short . '<br />';
    
    
            if (ftp_site($conn_id, "CHMOD $ftp_chmod $value_short")) { // <-------------- Use the relative path in the function
                echo 'CHMOD ' . $ftp_chmod . ' IS <span style="color: #00B200">SUCCESSFULL</span><br /><br />';
            }
            else {
                echo '<span style="color: crimson">CHMOD FAILED!</span><br /><br />';
            }
        }
        else {
            echo $path . ' -- ' . '<span style="color: crimson"><b>NOT EXIST</b></span><br />';
        } // end if ( is_dir($path) == true ) else
    
    } // end foreach ( $folder_path as $key => $value )
    
    ---- REST OF THE SCRIPT OMITED -----
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型