/** * @brief get content of a file * @param GET `path` * @return */ public function content() { $params = $this->input->post(); if (empty($params) || !isset($params['id']) || !isset($params['host']) || empty($params['host']) || !isset($params['login']) || empty($params['login']) || !isset($params['password']) || empty($params['password'])) { echo json_encode(array('result' => 'error', 'error' => 'missing parameters')); return; } // get the parameter $filePath = $params['id']; $filePath = str_replace('_SEP_', '/', $filePath); // connect to remote host $ssh = new ssh($params['host'], $params['login'], $params['password']); // if params['content'] was supplied, save the file, otherwise get the file if (isset($params['content'])) { file_put_contents($this->localTempFile, $params['content']); $result = $ssh->upload($this->localTempFile, $filePath); if ($result === false) { echo json_encode(array('result' => 'error', 'error' => 'cannot upload file')); return; } echo json_encode(array('result' => 'success')); } else { // download the file to temp local file $result = $ssh->download($filePath, $this->localTempFile); if ($result === false) { echo json_encode(array('result' => 'error', 'error' => 'cannot get remote file')); return; } echo json_encode(array('result' => 'success', 'content' => file_get_contents($this->localTempFile))); } }