diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 9baca991..da4c0294 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 @@ class Net_SFTP extends Net_SSH2 } 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 @@ class Net_SFTP extends Net_SSH2 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 @@ class Net_SFTP extends Net_SSH2 $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; + } }