1
0
mirror of https://github.com/danog/tgseclib.git synced 2024-12-11 08:39:43 +01:00

Merge branch 'master' of https://github.com/phpseclib/phpseclib into pmexts

This commit is contained in:
Patrick Monnerat 2012-11-08 12:23:03 +01:00
commit 4ad2ffe9d7

View File

@ -504,12 +504,10 @@ class Net_SFTP extends Net_SSH2 {
* Canonicalize the Server-Side Path Name * Canonicalize the Server-Side Path Name
* *
* SFTP doesn't provide a mechanism by which the current working directory can be changed, so we'll emulate it. Returns * SFTP doesn't provide a mechanism by which the current working directory can be changed, so we'll emulate it. Returns
* the absolute (canonicalized) path. If $mode is set to NET_SFTP_CONFIRM_DIR (as opposed to NET_SFTP_CONFIRM_NONE, * the absolute (canonicalized) path.
* which is what it is set to by default), false is returned if $dir is not a valid directory.
* *
* @see Net_SFTP::chdir() * @see Net_SFTP::chdir()
* @param String $dir * @param String $dir
* @param optional Integer $mode
* @return Mixed * @return Mixed
* @access private * @access private
*/ */
@ -544,7 +542,11 @@ class Net_SFTP extends Net_SSH2 {
$dir = $dir[0] == '/' ? '/' . rtrim(substr($dir, 1), '/') : rtrim($dir, '/'); $dir = $dir[0] == '/' ? '/' . rtrim(substr($dir, 1), '/') : rtrim($dir, '/');
if ($dir == '.' || $dir == $this->pwd) { if ($dir == '.' || $dir == $this->pwd) {
return $this->pwd . $file; $temp = $this->pwd;
if (!empty($file)) {
$temp.= '/' . $file;
}
return $temp;
} }
if ($dir[0] != '/') { if ($dir[0] != '/') {
@ -1207,11 +1209,40 @@ class Net_SFTP extends Net_SSH2 {
return false; return false;
} }
$dir = $this->_realpath(rtrim($dir, '/')); if ($dir[0] != '/') {
if ($dir === false) { $dir = $this->_realpath(rtrim($dir, '/'));
return false; if ($dir === false) {
return false;
}
if (!$this->_mkdir_helper($dir)) {
return false;
}
} else {
$dirs = explode('/', preg_replace('#^/|/(?=/)|/$#', '', $dir));
$temp = '';
foreach ($dirs as $dir) {
$temp.= '/' . $dir;
$result = $this->_mkdir_helper($temp);
}
if (!$result) {
return false;
}
} }
$this->_save_dir($dir);
return true;
}
/**
* Helper function for directory creation
*
* @param String $dir
* @return Boolean
* @access private
*/
function _mkdir_helper($dir)
{
// by not providing any permissions, hopefully the server will use the logged in users umask - their // by not providing any permissions, hopefully the server will use the logged in users umask - their
// default permissions. // default permissions.
if (!$this->_send_sftp_packet(NET_SFTP_MKDIR, pack('Na*N', strlen($dir), $dir, 0))) { if (!$this->_send_sftp_packet(NET_SFTP_MKDIR, pack('Na*N', strlen($dir), $dir, 0))) {
@ -1230,8 +1261,6 @@ class Net_SFTP extends Net_SSH2 {
return false; return false;
} }
$this->_save_dir($dir);
return true; return true;
} }