protected function filecopy($srcFile, $destFile)
 {
     if (AJXP_MetaStreamWrapper::nodesUseSameWrappers($srcFile, $destFile)) {
         $srcFilePath = str_replace($this->urlBase, "", $srcFile);
         $destFilePath = str_replace($this->urlBase, "", $destFile);
         $destDirPath = dirname($destFilePath);
         list($connection, $remote_base_path) = sftpAccessWrapper::getSshConnection($srcFile);
         $remoteSrc = $remote_base_path . $srcFilePath;
         $remoteDest = $remote_base_path . $destDirPath;
         $this->logDebug("SSH2 CP", array("cmd" => 'cp ' . $remoteSrc . ' ' . $remoteDest));
         ssh2_exec($connection, 'cp ' . $remoteSrc . ' ' . $remoteDest);
         AJXP_Controller::applyHook("node.change", array(new AJXP_Node($srcFile), new AJXP_Node($destFile), true));
     } else {
         parent::filecopy($srcFile, $destFile);
     }
 }
 /**
  * We have to override the standard copyOrMoveFile, as feof() does
  * not seem to work with ssh2.ftp stream... 
  * Maybe something to search hear http://www.mail-archive.com/php-general@lists.php.net/msg169992.html?
  *
  * @param string $destDir
  * @param string $srcFile
  * @param array $error
  * @param array $success
  * @param boolean $move
  */
 function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move = false)
 {
     $mess = ConfService::getMessages();
     $destFile = $this->urlBase . $destDir . "/" . basename($srcFile);
     $realSrcFile = $this->urlBase . $srcFile;
     if (!file_exists($realSrcFile)) {
         $error[] = $mess[100] . $srcFile;
         return;
     }
     if (dirname($realSrcFile) == dirname($destFile)) {
         if ($move) {
             $error[] = $mess[101];
             return;
         } else {
             $base = basename($srcFile);
             $i = 1;
             if (is_file($realSrcFile)) {
                 $dotPos = strrpos($base, ".");
                 if ($dotPos > -1) {
                     $radic = substr($base, 0, $dotPos);
                     $ext = substr($base, $dotPos);
                 }
             }
             // auto rename file
             $i = 1;
             $newName = $base;
             while (file_exists($this->urlBase . $destDir . "/" . $newName)) {
                 $suffix = "-{$i}";
                 if (isset($radic)) {
                     $newName = $radic . $suffix . $ext;
                 } else {
                     $newName = $base . $suffix;
                 }
                 $i++;
             }
             $destFile = $this->urlBase . $destDir . "/" . $newName;
         }
     }
     if (!is_file($realSrcFile)) {
         $errors = array();
         $succFiles = array();
         if ($move) {
             if (file_exists($destFile)) {
                 $this->deldir($destFile);
             }
             $res = rename($realSrcFile, $destFile);
         } else {
             $dirRes = $this->dircopy($realSrcFile, $destFile, $errors, $succFiles);
         }
         if (count($errors) || isset($res) && $res !== true) {
             $error[] = $mess[114];
             return;
         }
     } else {
         if ($move) {
             if (file_exists($destFile)) {
                 unlink($destFile);
             }
             $res = rename($realSrcFile, $destFile);
             AJXP_Controller::applyHook("move.metadata", array($realSrcFile, $destFile, false));
         } else {
             try {
                 // BEGIN OVERRIDING
                 list($connection, $remote_base_path) = sftpAccessWrapper::getSshConnection($realSrcFile);
                 $remoteSrc = $remote_base_path . $srcFile;
                 $remoteDest = $remote_base_path . $destDir;
                 AJXP_Logger::debug("SSH2 CP", array("cmd" => 'cp ' . $remoteSrc . ' ' . $remoteDest));
                 ssh2_exec($connection, 'cp ' . $remoteSrc . ' ' . $remoteDest);
                 AJXP_Controller::applyHook("move.metadata", array($realSrcFile, $destFile, true));
                 // END OVERRIDING
             } catch (Exception $e) {
                 $error[] = $e->getMessage();
                 return;
             }
         }
     }
     if ($move) {
         // Now delete original
         // $this->deldir($realSrcFile); // both file and dir
         $messagePart = $mess[74] . " " . SystemTextEncoding::toUTF8($destDir);
         if (RecycleBinManager::recycleEnabled() && $destDir == RecycleBinManager::getRelativeRecycle()) {
             RecycleBinManager::fileToRecycle($srcFile);
             $messagePart = $mess[123] . " " . $mess[122];
         }
         if (isset($dirRes)) {
             $success[] = $mess[117] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $messagePart . " (" . SystemTextEncoding::toUTF8($dirRes) . " " . $mess[116] . ") ";
         } else {
             $success[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $messagePart;
         }
     } else {
         if (RecycleBinManager::recycleEnabled() && $destDir == "/" . $this->repository->getOption("RECYCLE_BIN")) {
             RecycleBinManager::fileToRecycle($srcFile);
         }
         if (isset($dirRes)) {
             $success[] = $mess[117] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $mess[73] . " " . SystemTextEncoding::toUTF8($destDir) . " (" . SystemTextEncoding::toUTF8($dirRes) . " " . $mess[116] . ")";
         } else {
             $success[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $mess[73] . " " . SystemTextEncoding::toUTF8($destDir);
         }
     }
 }
 /**
  * Get ssh2 connection
  *
  * @param Repository $repoObject
  * @return Resource
  */
 protected static function getSftpResource($repoObject)
 {
     if (isset(self::$sftpResource) && self::$resourceRepoId == $repoObject->getId()) {
         return self::$sftpResource;
     }
     $callbacks = array('disconnect' => "disconnectedSftp", 'ignore' => "ignoreSftp", 'debug' => "debugSftp", 'macerror' => "macerrorSftp");
     $remote_serv = $repoObject->getOption("SERV");
     $remote_port = $repoObject->getOption("PORT");
     $credentials = AJXP_Safe::tryLoadingCredentialsFromSources(array(), $repoObject);
     $remote_user = $credentials["user"];
     $remote_pass = $credentials["password"];
     $connection = ssh2_connect($remote_serv, intval($remote_port), array(), $callbacks);
     ssh2_auth_password($connection, $remote_user, $remote_pass);
     self::$sftpResource = ssh2_sftp($connection);
     self::$resourceRepoId = $repoObject->getId();
     return self::$sftpResource;
 }
 /**
  * Get ssh2 connection
  *
  * @param Repository $repoObject
  * @return Resource
  */
 protected static function getSftpResource($repoObject)
 {
     if (isset(self::$sftpResource)) {
         return self::$sftpResource;
     }
     $callbacks = array('disconnect' => "disconnectedSftp", 'ignore' => "ignoreSftp", 'debug' => "debugSftp", 'macerror' => "macerrorSftp");
     $remote_serv = $repoObject->getOption("SERV");
     $remote_port = $repoObject->getOption("PORT");
     $remote_user = $repoObject->getOption("USER");
     $remote_pass = $repoObject->getOption("PASS");
     $connection = ssh2_connect($remote_serv, intval($remote_port), array(), $callbacks);
     ssh2_auth_password($connection, $remote_user, $remote_pass);
     self::$sftpResource = ssh2_sftp($connection);
     return self::$sftpResource;
 }