From: Vincent Vanwaelscappel Date: Thu, 19 Jan 2023 20:49:16 +0000 (+0100) Subject: wip #5661 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=8e9edc633eaa4098ac049d3a6438f2ea82820835;p=cubist_net.git wip #5661 @1 --- diff --git a/src/SSH2.php b/src/SSH2.php index 75d2bd5..6dfa0d8 100644 --- a/src/SSH2.php +++ b/src/SSH2.php @@ -10,6 +10,7 @@ class SSH2 { protected $_key = null; protected $_connection = null; protected $_sftp = null; + public $convertToCygwinPath = false; public function __construct($host, $username, $password, $port = 22) { $this->setHost($host) @@ -70,8 +71,9 @@ class SSH2 { return $this->_sftp; } + public function getSFTPWrapper() { - return 'ssh2.sftp://' . $this->getSFTPConnection() . '/'; + return 'ssh2.sftp://' . intval($this->getSFTPConnection()) . '/'; } public function filePutContents($filename, $data) { @@ -93,7 +95,10 @@ class SSH2 { } protected function _filename($filename) { - return $this->getSFTPWrapper() . ltrim($this->_escapeCygwin($filename), '/'); + if ($this->convertToCygwinPath) { + $filename = $this->_escapeCygwin($filename); + } + return $this->getSFTPWrapper() . ltrim($filename, '/'); } public function filesize($filename) { @@ -113,23 +118,26 @@ class SSH2 { /** * @param $local string - * @param $distant string + * @param $remote string * @param $mode int * @return bool */ - public function send($local, $distant, $mode = 0755) { - $dir = dirname($distant); + public function send($local, $remote, $mode = 0644) { + if (!file_exists($local)) { + throw new \Exception('Local file ' . $local . ' not found'); + } + $dir = dirname($remote); $this->mkdir($dir); - return ssh2_scp_send($this->getSFTPConnection(), $local, $distant, $mode); + return copy($local, $this->_filename($remote)); } /** - * @param $distant string + * @param $remote string * @param $local string * @return bool */ - public function recv($distant, $local) { - return ssh2_scp_recv($this->getSFTPConnection(), $distant, $local); + public function recv($remote, $local) { + return copy($this->_filename($remote), $local); }