Ejemplo n.º 1
0
 private function _put($srcFullPath, $srcRelPath)
 {
     $destRelPath = $this->_destDir . '/' . $srcRelPath;
     $this->controller->stdout("\n - " . $srcRelPath . "\t => " . $destRelPath);
     if (!$this->controller->dryRun) {
         if (is_dir($srcFullPath)) {
             $files = FileHelper::findFiles($srcFullPath, $this->_options);
             foreach ($files as $foundPath) {
                 $relativePath = substr($foundPath, strlen($this->_srcBaseDir) + 1);
                 $this->_sftpHelper->mkdir($destRelPath);
                 $this->_put($foundPath, $relativePath, $this->_srcBaseDir, $this->_destDir, $this->_options);
             }
         } elseif (FileHelper::filterPath($srcFullPath, $this->_options)) {
             $this->_sftpHelper->mkdir(dirname($destRelPath), -1, true);
             if ($this->_overwrite || !$this->_sftpHelper->fileExists($destRelPath)) {
                 $res = $this->_sftpHelper->put($destRelPath, $srcFullPath);
                 if (!$res) {
                     Log::logger()->addError('sftpPut: error uploading file {from} to {to}', ['from' => $srcFullPath, 'to' => $destRelPath]);
                 }
             } else {
                 $this->controller->stdout(' [skipped]', Console::FG_PURPLE);
             }
         }
     } else {
         $this->controller->stdout(' [dry run]', Console::FG_YELLOW);
     }
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function run(&$cmdParams, &$params)
 {
     $controller = $this->controller;
     $res = true;
     $connectionId = !empty($cmdParams[0]) ? $cmdParams[0] : '';
     $dir = !empty($cmdParams[1]) ? $cmdParams[1] : '';
     $mode = !empty($cmdParams[2]) ? $cmdParams[2] : -1;
     $recursive = !empty($cmdParams[3]) ? $cmdParams[3] : true;
     if (empty($connectionId) || empty($dir)) {
         Log::throwException('sftpMkdir: Please specify a valid connection id and directory');
     }
     /** @noinspection PhpUndefinedMethodInspection (provided by the SftpConnectReqs Behavior) */
     $connParams = $controller->getConnectionParams($connectionId);
     $controller->stdout(" " . $connectionId . " ", $connParams['sftpLabelColor'], Console::FG_BLACK);
     $controller->stdout(' Creating directory ');
     $controller->stdout($dir, Console::FG_CYAN);
     if (!$controller->dryRun) {
         // the getConnection method is provided by the SftpConnectReqs Behavior
         /** @noinspection PhpUndefinedMethodInspection */
         /** @var $connection Net_SFTP|resource */
         $connection = $controller->getConnection($connectionId);
         $sftpHelper = new SftpHelper($connectionId, $connection, $connParams);
         $res = $sftpHelper->mkdir($dir, $mode, $recursive);
         $sftpHelper->flushCache();
     } else {
         $controller->stdout(' [dry run]', Console::FG_YELLOW);
     }
     $controller->stdout("\n");
     return $res;
 }