From 16cd3ea9eee0de7e49de572eeca0f550028d6c5b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 20 Jan 2023 15:05:05 +0100 Subject: [PATCH] wip #5661 --- src/SSH2.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/SSH2.php b/src/SSH2.php index 6dfa0d8..27875ac 100644 --- a/src/SSH2.php +++ b/src/SSH2.php @@ -101,6 +101,10 @@ class SSH2 { return $this->getSFTPWrapper() . ltrim($filename, '/'); } + public function path($path) { + return $this->_filename($path); + } + public function filesize($filename) { return filesize($this->_filename($filename)); } @@ -128,7 +132,16 @@ class SSH2 { } $dir = dirname($remote); $this->mkdir($dir); - return copy($local, $this->_filename($remote)); + return $this->_copy($local, $this->_filename($remote)); + } + + protected function _copy($from, $to, $send = true) { + if (class_exists('Cubist\Util\Files\Files')) { + $res = \Cubist\Util\Files\Files::copyFile($from, $to); + } else { + $res = copy($from, $to); + } + return $res; } /** @@ -137,10 +150,9 @@ class SSH2 { * @return bool */ public function recv($remote, $local) { - return copy($this->_filename($remote), $local); + return $this->_copy($this->_filename($remote), $local, false); } - public function unlink($file) { if ($this->file_exists($file)) { return ssh2_sftp_unlink($this->getSFTPConnection(), $file); @@ -157,9 +169,8 @@ class SSH2 { stream_set_blocking($errorStream, true); stream_set_blocking($stream, true); - // Whichever of the two below commands is listed first will receive its appropriate output. The second command receives nothing - $res = array('output' => stream_get_contents($stream), - 'error' => stream_get_contents($errorStream)); + $stream_size_limit = 100000; + $res=['output'=>fread($stream,$stream_size_limit),'error'=>fread($errorStream,$stream_size_limit)]; // Close the streams fclose($errorStream); -- 2.39.5