flysystem-sftp icon indicating copy to clipboard operation
flysystem-sftp copied to clipboard

setting directoryPerm to 0755 not working

Open Malakarakesh1993 opened this issue 5 years ago • 4 comments

Here's my config. :

   'sftp' => [
        'driver' => 'sftp',
        'host'     => env('SFTP_HOST'),
        'port'     => 22,
        'username' => env('SFTP_USERNAME'),
        'root' => '/uploads/', 
        'privateKey' => env('SFTP_KEY_PATH'),
        'visibility' => 'public',
        'permPublic' => 0755,
        'directoryPerm' => 0755
    ]

   $remote_path = $clientName . '/' . $fileNameToStore;                    
   $ftp = Storage::disk('sftp')->put($remote_path, fopen($uploadedFile, 'r+'), 'public');

But the directoryPermission is always 0744.

File permission is changed to 0755 though.

Malakarakesh1993 avatar May 31 '19 06:05 Malakarakesh1993

the same for me

kevindesousa avatar Jun 17 '19 16:06 kevindesousa

I have the same problem. I think this has to do with umask rules but I have no idea how to bypass them. Umask 0022 converts a 0777 to 0755.

bzelba avatar Jun 18 '19 06:06 bzelba

I think it's caused by a parent class ... this below: https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Net/SFTP.php#L1700

Once changed that line to 0777 .. it works and set's proper permissions whatever typed in directoryPerm parameter.

atanas18 avatar Mar 25 '20 17:03 atanas18

The problem is that createDirectory() method in SftpAdapter does not make use of the $config parameter to use the directoryPerm if available.

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

    /**
     * @inheritdoc
     */
    public function createDir($dirname, Config $config)
    {
        $connection = $this->getConnection();

        if (! $connection->mkdir($dirname, $this->directoryPerm, true)) {
            return false;
        }

        return ['path' => $dirname];
    }

You can see that mkdir uses $this->directoryPerm without using the config like other functions. So it's kinda like a bug.

THE SOLUTION for this is to use the accessor method called setDirectoryPerm() and to set it manually each time like:

$filesystem = Storage::disk('sftp');
$filesystem->getDriver()->getAdapter()->setDirectoryPerm(0755);
$filesystem->put('dir1/dir2/test.txt', 'Hello World');

KeitelDOG avatar Dec 27 '20 20:12 KeitelDOG