Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting directoryPerm to 0755 not working #81

Open
Malakarakesh1993 opened this issue May 31, 2019 · 4 comments
Open

setting directoryPerm to 0755 not working #81

Malakarakesh1993 opened this issue May 31, 2019 · 4 comments

Comments

@Malakarakesh1993
Copy link

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.

@kevindesousa
Copy link

the same for me

@bzelba
Copy link

bzelba commented Jun 18, 2019

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.

@atanas18
Copy link

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.

@KeitelDOG
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants