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.
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.
In my case, it was enough to set directoryPerm
with the needed umask in the config of the sftpAdapter
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
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');