Skip to content

Commit

Permalink
Merge branch '2.0' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Mar 30, 2020
2 parents fc87edc + 7e67f88 commit 542bb6c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions phpseclib/Net/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1695,9 +1695,6 @@ public 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 @@ -1708,12 +1705,12 @@ public 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 @@ -1724,9 +1721,10 @@ public function mkdir($dir, $mode = -1, $recursive = false)
* @return bool
* @access private
*/
private function mkdir_helper($dir, $attr)
private function mkdir_helper($dir, $mode)
{
if (!$this->send_sftp_packet(NET_SFTP_MKDIR, Strings::packSSH2('s', $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, Strings::packSSH2('s', $dir) . "\0\0\0\0")) {
return false;
}

Expand All @@ -1742,6 +1740,10 @@ private function mkdir_helper($dir, $attr)
return false;
}

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

return true;
}

Expand Down

0 comments on commit 542bb6c

Please sign in to comment.