【问题标题】:Laravel filesystem sftp set umask for new foldersLaravel 文件系统 sftp 为新文件夹设置 umask
【发布时间】:2019-03-14 05:27:43
【问题描述】:

是否可以为新创建的文件夹设置 umask

Storage::disk('sftp')->put('/path/to/folder/new/test.txt', $contents);

在我的例子中,使用的 umask 是 744。是否可以为新创建的文件夹更改 umask

提前致谢。

【问题讨论】:

    标签: laravel filesystems sftp umask


    【解决方案1】:

    解决方案是在config.xml中使用'directoryPerm' => 0755,键值。配置:

    'disks' => [
        'remote-sftp' => [
            'driver' => 'sftp',
            'host' => '222.222.222.222',
            'port' => 22,
            'username' => 'user',
            'password' => 'password',
            'visibility' => 'public', // set to public to use permPublic, or private to use permPrivate
            'permPublic' => 0755, // whatever you want the public permission is, avoid 0777
            'root' => '/path/to/web/directory',
            'timeout' => 30,
            'directoryPerm' => 0755, // whatever you want
        ],
    ],
    

    在代码中,文件 /private/var/www/megalobiz/vendor/league/flysystem-sftp/src/StfpAdapter 中的类 League\Flysystem\Sftp\StfpAdapter 有两个重要的属性可以清楚地看到:

    /**
     * @var array
     */
    protected $configurable = ['host', 'hostFingerprint', 'port', 'username', 'password', 'useAgent', 'agent', 'timeout', 'root', 'privateKey', 'passphrase', 'permPrivate', 'permPublic', 'directoryPerm', 'NetSftpConnection'];
    
    /**
     * @var int
     */
    protected $directoryPerm = 0744;
    

    $configurable 是配置上述文件系统 sftp 驱动程序的所有可能键。您可以在配置文件中将directoryPerm0744 更改为0755

    'directoryPerm' => 0755,
    

    但是,因为在 StfpAdapter https://github.com/thephpleague/flysystem-sftp/issues/81 中存在类似的错误,它不会在 createDir 上使用 $config 参数:

    $filesystem = Storage::disk('remote-sftp');
    $filesystem->getDriver()->getAdapter()->setDirectoryPerm(0755);
    $filesystem->put('dir1/dir2/'.$filename, $contents);
    

    或者故意设置为public:

    $filesystem->put('dir1/dir2/'.$filename, $contents, 'public');
    

    【讨论】:

      【解决方案2】:

      就我而言,在sftpAdapter 的配置中使用所需的umask 设置directoryPerm 就足够了

      【讨论】:

      • 酷。刚刚发布了一个答案,但没有意识到你找到了它。通常,当您找到解决方案或有人发布解决方案时,您应该接受它作为答案,以便其他人可以轻松看到它,以免浪费太多时间。就我而言,如果你接受了你的回答,你会为我节省一整天的时间。
      【解决方案3】:

      你可以使用这个功能:

      File::makeDirectory($path, $mode = 0777, true, true);
      

      在您的情况下,只需将 $mode 更改为 0774 :

      Storage::disk('sftp')->makeDirectory($path, 0774);
      

      文档:https://laravel.com/docs/5.1/filesystem#introduction

      【讨论】:

      • 很遗憾没有。这将创建一个包含 0774 的文件夹。我需要 0775 和 0775 不工作
      • 尝试将 0774 替换为 0775
      猜你喜欢
      • 2012-09-08
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多