]> _ Git - cubist_net.git/commitdiff
wip #5661 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Jan 2023 20:49:16 +0000 (21:49 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Jan 2023 20:49:16 +0000 (21:49 +0100)
src/SSH2.php

index 75d2bd500b1e58a5ec804aac751217d13903575b..6dfa0d863e566d5c270ef2873c325236b4a8b0fc 100644 (file)
@@ -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);
        }