Skip to content

Commit

Permalink
SFTP: add enableDatePreservation() / disableDatePreservation()
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Jul 30, 2020
1 parent d077c7b commit ea653e1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions phpseclib/Net/SFTP.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
}

1 comment on commit ea653e1

@terrafrost
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1496

Please sign in to comment.