• Plesk Uservoice will be deprecated by October. Moving forward, all product feature requests and improvement suggestions will be managed through our new platform Plesk Productboard.
    To continue sharing your ideas and feedback, please visit features.plesk.com

Issue FileManager and ServerFileManager permission issue

sfsdg

New Pleskian
I'm need to copy subdomain files to new domain folder, i have a custom extension. This extension using pm_ServerFileManager class's copyFile method. But files are copying with root user? If I use pm_FileManager extension return Permission error like "filemng failed: filemng: stat failed: Permission denied. System error 13: Permission denied"

Here is my code;

PHP:
protected function _run()
    {
        $from = $this->_params["from"];
        $to = $this->_params["to"];
        $defaultDbUsername = $this->_params["defaultDbUsername"];
        $defaultDbPassword = $this->_params["defaultDbPassword"];

        $domain = new \pm_Domain();

        $fromDomain =  $domain->getByDomainId($from);
        $toDomain =  $domain->getByDomainId($to);
  
        $fromDomainDocumentRoot = $fromDomain->getDocumentRoot();
        $toDomainDocumentRoot = $toDomain->getDocumentRoot();

        $fileManager = new \pm_FileManager($to);

        //Yükleme yapılacak site klsörünü temizleme
        $toFilePath = $fileManager->scanDir($toDomainDocumentRoot, true);
        foreach ($toFilePath as $value) {
            $fileManager->removeFile($toDomainDocumentRoot . "/" . $value);
        }

        //Wordpress yükleme
        $fromFilePath = $fileManager->scanDir($fromDomainDocumentRoot, true);
        foreach ($fromFilePath as $value) {
            $fileManager->copyFile($fromDomainDocumentRoot . "/" . $value, $toDomainDocumentRoot);
            //$fileManager->chmod($fromDomainDocumentRoot . "/" . $value, "755");
        }

        $toFileContents = $fileManager->fileGetContents($toDomainDocumentRoot . "/wp-config.php");

        $domainName = $domain->getName();

        $toFileContents = preg_replace('/define\(\'DB_NAME\', \'(.*?)\'\);/', "define('DB_NAME', '$domainName');", $toFileContents);
        $toFileContents = preg_replace('/define\(\'DB_USER\', \'(.*?)\'\);/', "define('DB_USER', '$defaultDbUsername');", $toFileContents);
        $toFileContents = preg_replace('/define\(\'DB_PASSWORD\', \'(.*?)\'\);/', "define('DB_PASSWORD', '$defaultDbPassword');", $toFileContents);

        $fileManager->filePutContents($toDomainDocumentRoot . "/wp-config.php", $toFileContents);


        return [
            'status' => true,
        ];
    }

This return like that result
Code:
<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.8.0">
  <extension>
    <call>
      <result>
        <status>error</status>
        <errcode>1002</errcode>
        <errtext>filemng failed: filemng: stat failed: Permission denied

System error 13: Permission denied</errtext>
      </result>
    </call>
  </extension>
</packet>

If I use pm_ServerFileManager class code works perfectly but files are copy with root user;
roo_problem.png


Edit:
I'm researching already for this post. And everybody says like "this is not possible". But wp-toolkit and "Plesk Web Clone" doing this, how?
 
Last edited:
If customers are custom (not Administrator) and different or same I can copy files between domains. This is local, if I go to real server on the I can't do this.
 
Back
Top