Example #1
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return \EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $ziper->logger->log('Executing FTP transfer');
     $user = trim($this->user);
     $pass = trim($this->pass);
     if ('' == $user) {
         $text = 'FTP User';
         $command = escapeshellcmd('DISPLAY=:0 XAUTHORITY=/home/elkuku/.Xauthority' . ' kdialog --title "' . $text . '" --inputbox "' . $text . '"');
         $ziper->logger->log('Executing: ' . $command);
         $user = shell_exec($command . ' 2>&1');
         if ('' == $user) {
             $ziper->logger->log('ERROR: No user name given', 'FTP user', JLog::ERROR);
             return $this;
         }
     }
     if ('' == $pass) {
         $text = 'FTP Password';
         $command = escapeshellcmd('DISPLAY=:0 XAUTHORITY=/home/elkuku/.Xauthority' . ' kdialog --title "' . $text . '" --inputbox "' . $text . '"');
         $ziper->logger->log('Executing: ' . $command);
         $pass = shell_exec($command . ' 2>&1');
         if ('' == $pass) {
             $ziper->logger->log('ERROR: No password given', 'FTP user', JLog::ERROR);
             return $this;
         }
     }
     $ftp = EcrFtp::getClient($this->host, $this->port, null, $user, $pass);
     $files = explode(',', $this->files);
     $packages = $ziper->getCreatedFiles();
     foreach ($files as $file) {
         $file = trim($file);
         $path = '';
         $fileName = '';
         switch ($file) {
             case 'package':
                 $path = $packages[0]->path;
                 break;
             default:
                 $ziper->logger->log('ERROR: Unknown file type: ' . $file, 'FTP transfer', JLog::ERROR);
         }
         $remote = null;
         if ($this->folder) {
             $remote = $this->folder . '/' . basename($path);
         }
         if (false == $ftp->store($path, $remote)) {
             //@todo: deprecated JError
             $error = JError::getError();
             $ziper->logger->log('ERROR: ' . $error, 'FTP transfer (JFTP)', JLog::ERROR);
         } else {
             $ziper->logger->log('File transfered: ' . $fileName);
         }
     }
     return $this;
 }
Example #2
0
 /**
  * @throws Exception
  * @return mixed|void
  */
 protected function connect()
 {
     $credentials = new stdClass();
     /* @var JInput $input */
     $input = JFactory::getApplication()->input;
     $credentials->host = $input->get('ftpHost');
     $credentials->port = $input->getInt('ftpPort');
     $credentials->directory = $input->getString('ftpDirectory');
     $credentials->downloads = $input->getString('ftpDownloads');
     $credentials->user = $input->get('ftpUser');
     $credentials->pass = $input->get('ftpPass');
     $options = null;
     JLog::add('| ^^ ' . sprintf(jgettext('Connecting to %s ...'), $credentials->host));
     $this->ftp = EcrFtp::getClient($credentials->host, $credentials->port, $options, $credentials->user, $credentials->pass);
     if (!$this->ftp->isConnected()) {
         throw new Exception(jgettext('Unable to connect to FTP server'));
     }
     $this->credentials = $credentials;
 }