SFTP: add enableDatePreservation() / disableDatePreservation()

This commit is contained in:
terrafrost 2020-07-30 09:12:23 -05:00
parent d077c7b296
commit ea653e1b01

View File

@ -300,6 +300,16 @@ class Net_SFTP extends Net_SSH2
*/ */
var $requestBuffer = array(); var $requestBuffer = array();
/**
* Preserve timestamps on file downloads / uploads
*
* @see self::get()
* @see self::put()
* @var bool
* @access private
*/
var $preserveTime = false;
/** /**
* Default Constructor. * Default Constructor.
* *
@ -2136,6 +2146,11 @@ class Net_SFTP extends Net_SSH2
} }
if ($mode & NET_SFTP_LOCAL_FILE) { if ($mode & NET_SFTP_LOCAL_FILE) {
if ($this->preserveTime) {
$stat = fstat($fp);
$this->touch($remote_file, $stat['mtime'], $stat['atime']);
}
fclose($fp); fclose($fp);
} }
@ -2353,6 +2368,11 @@ class Net_SFTP extends Net_SSH2
if ($fclose_check) { if ($fclose_check) {
fclose($fp); fclose($fp);
if ($this->preserveTime) {
$stat = $this->stat($remote_file);
touch($local_file, $stat['mtime'], $stat['atime']);
}
} }
if (!$this->_close_handle($handle)) { if (!$this->_close_handle($handle)) {
@ -3237,4 +3257,24 @@ class Net_SFTP extends Net_SSH2
$this->pwd = false; $this->pwd = false;
parent::_disconnect($reason); parent::_disconnect($reason);
} }
/**
* Enable Date Preservation
*
* @access public
*/
function enableDatePreservation()
{
$this->preserveTime = true;
}
/**
* Disable Date Preservation
*
* @access public
*/
function disableDatePreservation()
{
$this->preserveTime = false;
}
} }