From 5979ed571f54e6f5bc63ce8e468145ea08388418 Mon Sep 17 00:00:00 2001 From: David Hedberg Date: Fri, 2 Jun 2017 09:58:28 +0200 Subject: [PATCH] SFTP: Add a NO_REALPATH option to put() --- phpseclib/Net/SFTP.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 40c97daf..52a4d2e5 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -96,25 +96,29 @@ define('NET_SFTP_CHANNEL', 0x100); /** * Reads data from a local file. */ -define('NET_SFTP_LOCAL_FILE', 1); +define('NET_SFTP_LOCAL_FILE', 0x1); /** * Reads data from a string. */ // this value isn't really used anymore but i'm keeping it reserved for historical reasons -define('NET_SFTP_STRING', 2); +define('NET_SFTP_STRING', 0x2); /** * Reads data from callback: * function callback($length) returns string to proceed, null for EOF */ -define('NET_SFTP_CALLBACK', 16); +define('NET_SFTP_CALLBACK', 0x10); /** * Resumes an upload */ -define('NET_SFTP_RESUME', 4); +define('NET_SFTP_RESUME', 0x4); /** * Append a local file to an already existing remote file */ -define('NET_SFTP_RESUME_START', 8); +define('NET_SFTP_RESUME_START', 0x8); +/** + * Skip canonicalizing the remote path + */ +define('NET_SFTP_NO_REALPATH', 0x20); /**#@-*/ /** @@ -1887,8 +1891,9 @@ class Net_SFTP extends Net_SSH2 * Currently, only binary mode is supported. As such, if the line endings need to be adjusted, you will need to take * care of that, yourself. * - * $mode can take an additional two parameters - NET_SFTP_RESUME and NET_SFTP_RESUME_START. These are bitwise AND'd with - * $mode. So if you want to resume upload of a 300mb file on the local file system you'd set $mode to the following: + * $mode can take three additional parameters - NET_SFTP_RESUME, NET_SFTP_RESUME_START and NET_SFTP_NO_REALPATH. These + * are bitwise AND'd with $mode. So if you want to resume upload of a 300mb file on the local file system you'd set $mode + * to the following: * * NET_SFTP_LOCAL_FILE | NET_SFTP_RESUME * @@ -1904,6 +1909,9 @@ class Net_SFTP extends Net_SSH2 * * Setting $local_start to > 0 or $mode | NET_SFTP_RESUME_START doesn't do anything unless $mode | NET_SFTP_LOCAL_FILE. * + * Passing self::NO_REALPATH skips canonicalization of the remote path; $remote_file will be passed verbatim to the + * remote host. + * * @param string $remote_file * @param string|resource $data * @param int $mode @@ -1920,9 +1928,11 @@ class Net_SFTP extends Net_SSH2 return false; } - $remote_file = $this->_realpath($remote_file); - if ($remote_file === false) { - return false; + if (!($mode & NET_SFTP_NO_REALPATH)) { + $remote_file = $this->_realpath($remote_file); + if ($remote_file === false) { + return false; + } } $this->_remove_from_stat_cache($remote_file);