示例#1
0
文件: Sftp.php 项目: Leemo/deployer
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     foreach ($this->params() as $param => $value) {
         $this->_params[$param] = \Deployer::applyGlobalParams($value);
     }
     $ssh = new \Net_SSH2($this->param('host'), $this->param('port'));
     if (!$ssh->login($this->param('username'), $this->param('password'))) {
         throw new \Deployer\TaskException('Can\'t connect to remote host');
     }
     $scp = new \Net_SCP($ssh);
     $scp->put($this->param('dest'), file_get_contents($this->param('file')));
     $info = sprintf('Filesize: %d bytes', filesize($this->param('file')));
     return $this->info($info);
 }
示例#2
0
 function ssh2_scp_send($session, $local_file, $remote_file, $create_mode = 0644)
 {
     $scp = new Net_SCP($session);
     return $scp->put($remote_file, $local_file, NET_SCP_LOCAL_FILE);
 }
示例#3
0
 /**
  * Cargar el video al servidor secundario 
  **/
 function cargar_video()
 {
     if ($this->ion_auth->logged_in()) {
         $email = $this->ion_auth->get_user_email($this->ion_auth->get_user_id());
         $dir_upload = "/opt/lampp/htdocs/videos/" . $email . "/";
         $size = $_FILES["archivo"]['size'];
         $type = $_FILES["archivo"]['type'];
         $name = $_FILES["archivo"]['name'];
         $find = array(" ", "(", ")");
         $name = str_replace($find, '_', $name);
         $dir_archivo = $dir_upload . $name;
         $nombre = isset($_POST['nombre']) ? $_POST['nombre'] : null;
         $descripcion = isset($_POST['descripcion']) ? $_POST['descripcion'] : null;
         $categoria = isset($_POST['categoria']) ? $_POST['categoria'] : null;
         if (!empty($nombre) || !empty($categoria) || !empty($descripcion) || strlen($descripcion) < 150 || strlen($nombre) < 30 || strlen($categoria) < 30 || $nombre != null || $descripcion != null || $categoria != null) {
             $datos = array('name_video' => $email . " - " . $_POST['nombre'], 'date_up' => date('Y-m-d H:i:s'), 'desc' => $_POST['descripcion'], 'ruta' => '/videos/' . $email . '/' . $name, 'ruta_img' => '/videos/' . $email . '/' . $name . '.png', 'categoria' => $_POST['categoria'], 'users_id' => $this->ion_auth->get_user_id());
             if ($_FILES["archivo"]["type"] == "video/flv" || $_FILES["archivo"]["type"] == "video/mp4" || $_FILES["archivo"]["type"] == "video/avi" || $_FILES["archivo"]["type"] == "video/mpeg" || $_FILES["archivo"]["type"] == "video/mov" || $_FILES["archivo"]["type"] == "video/wmv" || $_FILES["archivo"]["type"] == "video/webm" || $_FILES["archivo"]["type"] == "video/ogg") {
                 if ($_FILES['archivo']['size'] < 1000000000) {
                     if (move_uploaded_file($_FILES['archivo']['tmp_name'], $dir_archivo)) {
                         chmod($dir_archivo, 0777);
                         set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/lampp/htdocs/feitube/application/libraries/phpseclib');
                         include 'Net/SSH2.php';
                         include 'Net/SCP.php';
                         $ssh = new Net_SSH2($this->servidor_sec, 22, 500);
                         if (!$ssh->login('seat', 's')) {
                             exit('Login Failed');
                         }
                         $scp = new Net_SCP($ssh);
                         if (!$scp->put($dir_archivo, $dir_archivo, NET_SCP_LOCAL_FILE)) {
                             throw new Exception("Failed to send file");
                         }
                         $ssh->exec("ffmpeg -i " . $dir_archivo . " -ss 00:00:01 -vframes 1 " . $dir_archivo . ".png");
                         $ssh->exec("ffmpeg -i " . $dir_archivo . " -strict -2 -vcodec libx264 -crf 100 " . $dir_archivo . ".mp4");
                         $ssh->exec("ffmpeg -i " . $dir_archivo . " -acodec libvorbis -vcodec libtheora -ac 2 -ab 96k -ar 44100 -b:v 819200 -crf 200 " . $dir_archivo . ".ogv");
                         $ssh->exec("ffmpeg -i " . $dir_archivo . " -c:v libvpx -crf 20 -b:v 1M -c:a libvorbis " . $dir_archivo . ".webm");
                         $this->ion_auth->insert_video($datos);
                         redirect('videos/index', 'refresh');
                     } else {
                         redirect('videos/upload', 'refresh');
                     }
                 } else {
                     redirect('videos/upload', 'refresh');
                 }
             } else {
                 redirect('videos/upload', 'refresh');
             }
         } else {
             redirect('videos/upload', 'refresh');
         }
     } else {
         redirect('videos/login', 'refresh');
     }
 }
示例#4
0
 /**
  * ???
  *
  * @param ???
  * @param ???
  * @param string[][] $data Die Serverdaten
  * @return ???
  */
 public static function SendeDateien($files, $filesAddresses, $data)
 {
     $mainPath = dirname(__FILE__) . '/../..';
     if ($data['ZV']['zv_type'] == 'local' || $data['ZV']['zv_type'] == '') {
         // leer
     } elseif ($data['ZV']['zv_type'] == 'ssh') {
         // Dateien senden
         if (!is_array($files)) {
             $files = array($files);
         }
         $allPaths = array();
         foreach ($filesAddresses as $addresses) {
             $allPaths[] = dirname($addresses);
         }
         $allPaths = array_unique($allPaths);
         $allPaths = array_values($allPaths);
         for ($i = 0; $i < count($allPaths) - 1; $i++) {
             if (strpos($allPaths[$i + 1] . '/', $allPaths[$i] . '/') === 0) {
                 $allPaths[$i] = null;
             }
         }
         $ssh = Zugang::Verbinden($data);
         foreach ($allPaths as $path) {
             if ($path != null) {
                 $command = '$path="' . $path . '"; $e=explode("/", ltrim($path,"/")); $c=count($e); $cp=$e[0]; for($i=1;$i<$c;$i++){if(!is_dir($cp) && !@mkdir($cp,0775)){return false;} chmod($cp,0775);$cp.="/".$e[$i];} @mkdir($path,0775);chmod($path,0775);return true;';
                 $command = Zugang::checkServerType($ssh, $command);
                 if (count($ssh->channel_status) > 0 && $ssh->channel_status[0] != 97) {
                     $ssh = Zugang::Verbinden($data);
                 }
                 $ssh->exec('php -r ' . $command);
             }
         }
         $zip = new ZipArchive();
         Einstellungen::generatepath(dirname(__FILE__) . '/../temp');
         if ($zip->open(dirname(__FILE__) . '/../temp/data.zip', ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === TRUE) {
             for ($i = 0; $i < count($files); $i++) {
                 if (file_exists($files[$i]) && is_readable($files[$i])) {
                     $zip->addFromString($filesAddresses[$i], file_get_contents($files[$i]));
                 }
             }
             $zip->close();
         }
         if (count($ssh->channel_status) > 0 && $ssh->channel_status[0] != 97) {
             $ssh = Zugang::Verbinden($data);
         }
         $scp = new Net_SCP($ssh);
         if (count($ssh->channel_status) > 0 && $ssh->channel_status[0] != 97) {
             $ssh = Zugang::Verbinden($data);
             $scp = new Net_SCP($ssh);
         }
         $scp->put('data.zip', dirname(__FILE__) . '/../temp/data.zip', NET_SCP_LOCAL_FILE);
         $command = '$zip = new ZipArchive;$zip->open("data.zip");$zip->extractTo(".");$zip->close();unlink("data.zip");';
         if (count($ssh->channel_status) > 0 && $ssh->channel_status[0] != 97) {
             $ssh = Zugang::Verbinden($data);
             $scp = new Net_SCP($ssh);
         }
         $command = Zugang::checkServerType($ssh, $command);
         $ssh->exec('php -r ' . $command);
         $ssh->disconnect();
         if (isset($result['fail'])) {
             $fail = $result['fail'];
             unset($result['fail']);
         }
         if (isset($result['errno'])) {
             $errno = $result['errno'];
             unset($result['errno']);
         }
         if (isset($result['error'])) {
             $error = $result['error'];
             unset($result['error']);
         }
     } else {
         return array();
     }
 }
示例#5
0
 public function SCP($pDest, $pContent)
 {
     $scp = new Net_SCP($this->ssh_conn);
     $scp->put($pDest, $pContent);
 }