thephpleague / flysystem-sftp

[READ-ONLY SUBSPLIT] Flysystem Adapter for SFTP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setting directoryPerm to 0755 not working

Malakarakesh1993 opened this issue · 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.

the same for me

commented

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.

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.

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');