2

is it possible to set a umask for new created folders

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

In my case, the used umask is 744. Is it possible to change the umask for new created folders?

Thanks in advance.

Smoky
  • 127
  • 1
  • 2
  • 12

3 Answers3

1

In my case, it was enough to set directoryPerm with the needed umask in the config of the sftpAdapter

Smoky
  • 127
  • 1
  • 2
  • 12
  • Cool. Just posted an answer, but didn't realized you found it. Normally when you find a solution, or someone post a solution, you should accept it as answer, so other people can see it easily to avoid losing much time. In my case, if you had accepted your answer, you would have saved me a full day. – KeitelDOG Dec 25 '20 at 17:40
0

You can use this function :

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

In your case, just change the $mode to 0774 :

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

Documentation : https://laravel.com/docs/5.1/filesystem#introduction

0

The solution is to use the 'directoryPerm' => 0755, key value in config. The config:

'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
    ],
],

And in the codes, class League\Flysystem\Sftp\StfpAdapter in file /private/var/www/megalobiz/vendor/league/flysystem-sftp/src/StfpAdapter , there is 2 important attributes to see clearly:

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

/**
 * @var int
 */
protected $directoryPerm = 0744;

The $configurable is all possible keys to configure filesystem sftp driver above. You can change directoryPerm from 0744 to 0755 in config file:

'directoryPerm' => 0755,

HOWEVER, because there is kind a like a Bug in StfpAdapter https://github.com/thephpleague/flysystem-sftp/issues/81 that won't use the $config parameter on createDir:

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

Or set it with public in purpose:

$filesystem->put('dir1/dir2/'.$filename, $contents, 'public');
KeitelDOG
  • 4,750
  • 4
  • 18
  • 33