From ea653e1b012a71d6a194452421bb9cdef2cab827 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 30 Jul 2020 09:12:23 -0500 Subject: [PATCH] SFTP: add enableDatePreservation() / disableDatePreservation() --- phpseclib/Net/SFTP.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 9baca9910..da4c02940 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -300,6 +300,16 @@ class Net_SFTP extends Net_SSH2 */ var $requestBuffer = array(); + /** + * Preserve timestamps on file downloads / uploads + * + * @see self::get() + * @see self::put() + * @var bool + * @access private + */ + var $preserveTime = false; + /** * Default Constructor. * @@ -2136,6 +2146,11 @@ function put($remote_file, $data, $mode = NET_SFTP_STRING, $start = -1, $local_s } if ($mode & NET_SFTP_LOCAL_FILE) { + if ($this->preserveTime) { + $stat = fstat($fp); + $this->touch($remote_file, $stat['mtime'], $stat['atime']); + } + fclose($fp); } @@ -2353,6 +2368,11 @@ function get($remote_file, $local_file = false, $offset = 0, $length = -1, $prog if ($fclose_check) { fclose($fp); + + if ($this->preserveTime) { + $stat = $this->stat($remote_file); + touch($local_file, $stat['mtime'], $stat['atime']); + } } if (!$this->_close_handle($handle)) { @@ -3237,4 +3257,24 @@ function _disconnect($reason) $this->pwd = false; parent::_disconnect($reason); } + + /** + * Enable Date Preservation + * + * @access public + */ + function enableDatePreservation() + { + $this->preserveTime = true; + } + + /** + * Disable Date Preservation + * + * @access public + */ + function disableDatePreservation() + { + $this->preserveTime = false; + } }