IT序号网

php之Directadmin 更改文件多个域

webabcd 2026年09月08日 编程语言 173 0

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

8年前关闭。




Improve this question




在带有 DirectAdmin 的服务器上,我托管了大约 80 个网站。现在我想在每个网站上更新 CKEditor。此 CKEditor 位于同一文件夹中的每个网站上。喜欢:public_html/admin/plugin/CKeditor

是否有任何选项可以制作脚本或将新的 CKEditor 上传到所有具有 CKEditor 映射的域?

请您参考如下方法:

您可以编写一个脚本以 FTP 上传到您的所有站点。您必须创建一个对象数组/列表,其中包含您的 FTP 信息,例如 IP 地址、用户名和密码。然后遍历对象列表并将您的文件上传到正确的目录。

您可能还想删除现有目录。我建议首先在单个站点上尝试此操作,以查看该过程是否有效。然后你可以尝试一次做两三个,看看有没有错误。然后,您可以运行剩余的 70-80。

例如,查看从 php 站点获取的这段代码:

<?php 
 
class SFTPConnection 
{ 
    private $connection; 
    private $sftp; 
 
    public function __construct($host, $port=22) 
    { 
        $this->connection = @ssh2_connect($host, $port); 
        if (! $this->connection) 
            throw new Exception("Could not connect to $host on port $port."); 
    } 
 
    public function login($username, $password) 
    { 
        if (! @ssh2_auth_password($this->connection, $username, $password)) 
            throw new Exception("Could not authenticate with username $username " . 
                                "and password $password."); 
 
        $this->sftp = @ssh2_sftp($this->connection); 
        if (! $this->sftp) 
            throw new Exception("Could not initialize SFTP subsystem."); 
    } 
 
    public function uploadFile($local_file, $remote_file) 
    { 
        $sftp = $this->sftp; 
        $stream = @fopen("ssh2.sftp://$sftp$remote_file", 'w'); 
 
        if (! $stream) 
            throw new Exception("Could not open file: $remote_file"); 
 
        $data_to_send = @file_get_contents($local_file); 
        if ($data_to_send === false) 
            throw new Exception("Could not open local file: $local_file."); 
 
        if (@fwrite($stream, $data_to_send) === false) 
            throw new Exception("Could not send data from file: $local_file."); 
 
        @fclose($stream); 
    } 
} 
 
try 
{ 
    $sftp = new SFTPConnection("localhost", 22); 
    $sftp->login("username", "password"); 
    $sftp->uploadFile("/tmp/to_be_sent", "/tmp/to_be_received"); 
} 
catch (Exception $e) 
{ 
    echo $e->getMessage() . "\n"; 
} 
 
?> 

引用。 http://www.php.net/manual/en/function.ssh2-sftp.php#94651

有了它,您可以登录并上传文件。您只需修改它以遍历站点列表并遍历您要上传的整个目录。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!