Skip to content

Commit

Permalink
SFTP: change the mode with a SETSTAT instead of MKDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Mar 28, 2020
1 parent 645dc5c commit 5e2951f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions phpseclib/Net/SFTP.php
Expand Up @@ -1831,9 +1831,6 @@ function mkdir($dir, $mode = -1, $recursive = false)
}

$dir = $this->_realpath($dir);
// by not providing any permissions, hopefully the server will use the logged in users umask - their
// default permissions.
$attr = $mode == -1 ? "\0\0\0\0" : pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);

if ($recursive) {
$dirs = explode('/', preg_replace('#/(?=/)|/$#', '', $dir));
Expand All @@ -1844,12 +1841,12 @@ function mkdir($dir, $mode = -1, $recursive = false)
for ($i = 0; $i < count($dirs); $i++) {
$temp = array_slice($dirs, 0, $i + 1);
$temp = implode('/', $temp);
$result = $this->_mkdir_helper($temp, $attr);
$result = $this->_mkdir_helper($temp, $mode);
}
return $result;
}

return $this->_mkdir_helper($dir, $attr);
return $this->_mkdir_helper($dir, $mode);
}

/**
Expand All @@ -1859,9 +1856,10 @@ function mkdir($dir, $mode = -1, $recursive = false)
* @return bool
* @access private
*/
function _mkdir_helper($dir, $attr)
function _mkdir_helper($dir, $mode)
{
if (!$this->_send_sftp_packet(NET_SFTP_MKDIR, pack('Na*a*', strlen($dir), $dir, $attr))) {
// send SSH_FXP_MKDIR without any attributes (that's what the \0\0\0\0 is doing)
if (!$this->_send_sftp_packet(NET_SFTP_MKDIR, pack('Na*a*', strlen($dir), $dir, "\0\0\0\0"))) {
return false;
}

Expand All @@ -1880,6 +1878,10 @@ function _mkdir_helper($dir, $attr)
return false;
}

if ($mode !== -1) {
$this->chmod($mode, $dir);
}

return true;
}

Expand Down

1 comment on commit 5e2951f

@terrafrost
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1463

Please sign in to comment.