mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 03:27:31 +00:00
SFTP: Add enablePathCanonicalization()/disablePathCanonicalization()
This commit is contained in:
parent
0bb6c9b974
commit
bbf467babd
@ -199,7 +199,7 @@ class Net_SFTP extends Net_SSH2
|
||||
* Current working directory
|
||||
*
|
||||
* @var string
|
||||
* @see self::_realpath()
|
||||
* @see self::realpath()
|
||||
* @see self::chdir()
|
||||
* @access private
|
||||
*/
|
||||
@ -277,6 +277,20 @@ class Net_SFTP extends Net_SSH2
|
||||
*/
|
||||
var $sortOptions = array();
|
||||
|
||||
/**
|
||||
* Canonicalization Flag
|
||||
*
|
||||
* Determines whether or not paths should be canonicalized before being
|
||||
* passed on to the remote server.
|
||||
*
|
||||
* @see self::enablePathCanonicalization()
|
||||
* @see self::disablePathCanonicalization()
|
||||
* @see self::realpath()
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $canonicalize_paths = true;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
@ -630,6 +644,26 @@ class Net_SFTP extends Net_SSH2
|
||||
$this->stat_cache = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable path canonicalization
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function enablePathCanonicalization()
|
||||
{
|
||||
$this->canonicalize_paths = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable path canonicalization
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function disablePathCanonicalization()
|
||||
{
|
||||
$this->canonicalize_paths = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current directory name
|
||||
*
|
||||
@ -688,13 +722,20 @@ class Net_SFTP extends Net_SSH2
|
||||
* 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 canonicalize_paths has been disabled using disablePathCanonicalization(), $path is returned as-is.
|
||||
*
|
||||
* @see self::chdir()
|
||||
* @see self::disablePathCanonicalization()
|
||||
* @param string $path
|
||||
* @return mixed
|
||||
* @access private
|
||||
*/
|
||||
function _realpath($path)
|
||||
{
|
||||
if (!$this->canonicalize_paths) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
if ($this->pwd === false) {
|
||||
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.9
|
||||
if (!$this->_send_sftp_packet(NET_SFTP_REALPATH, pack('Na*', strlen($path), $path))) {
|
||||
@ -1349,7 +1390,7 @@ class Net_SFTP extends Net_SSH2
|
||||
/**
|
||||
* Returns general information about a file or symbolic link
|
||||
*
|
||||
* Determines information without calling Net_SFTP::_realpath().
|
||||
* Determines information without calling Net_SFTP::realpath().
|
||||
* The second parameter can be either NET_SFTP_STAT or NET_SFTP_LSTAT.
|
||||
*
|
||||
* @param string $filename
|
||||
@ -1510,7 +1551,7 @@ class Net_SFTP extends Net_SSH2
|
||||
return true;
|
||||
}
|
||||
|
||||
$filename = $this->_realPath($filename);
|
||||
$filename = $this->realpath($filename);
|
||||
// rather than return what the permissions *should* be, we'll return what they actually are. this will also
|
||||
// tell us if the file actually exists.
|
||||
// incidentally, SFTPv4+ adds an additional 32-bit integer field - flags - to the following:
|
||||
|
Loading…
Reference in New Issue
Block a user