首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Laravel文件系统sftp为新文件夹设置umask

Laravel文件系统sftp为新文件夹设置umask
EN

Stack Overflow用户
提问于 2018-10-09 12:21:34
回答 3查看 867关注 0票数 2

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

代码语言:javascript
运行
复制
Storage::disk('sftp')->put('/path/to/folder/new/test.txt', $contents);

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

提前谢谢。

EN

回答 3

Stack Overflow用户

发布于 2018-10-09 13:30:18

在我的示例中,只需在directoryPerm的配置中使用所需的umask设置sftpAdapter即可。

票数 1
EN

Stack Overflow用户

发布于 2018-10-09 12:27:27

您可以使用此函数:

代码语言:javascript
运行
复制
File::makeDirectory($path, $mode = 0777, true, true);

在您的示例中,只需将$mode更改为0774:

代码语言:javascript
运行
复制
Storage::disk('sftp')->makeDirectory($path, 0774);

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

票数 0
EN

Stack Overflow用户

发布于 2020-12-25 17:36:51

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

代码语言:javascript
运行
复制
'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
    ],
],

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

代码语言:javascript
运行
复制
/**
 * @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

代码语言:javascript
运行
复制
'directoryPerm' => 0755,

但是,因为在StfpAdapter https://github.com/thephpleague/flysystem-sftp/issues/81中有一种类似于Bug的类型,它不会在createDir上使用$config参数

代码语言:javascript
运行
复制
$filesystem = Storage::disk('remote-sftp');
$filesystem->getDriver()->getAdapter()->setDirectoryPerm(0755);
$filesystem->put('dir1/dir2/'.$filename, $contents);

或以公众为目的:

代码语言:javascript
运行
复制
$filesystem->put('dir1/dir2/'.$filename, $contents, 'public');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52720952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档