/** * Runs the FTP deploy task. * * @return Result The result of the task. */ public function run() { $ftp = new \Ftp(); // connect to the server try { if ($this->useSSL) { $ftp->sslConnect($this->host); } else { $ftp->connect($this->host); } $ftp->login($this->user, $this->password); // create the target directory if it does not exist $ftp->chdir('/'); if (!$ftp->fileExists($this->targetDirectory)) { $this->printTaskInfo('Creating directory: ' . $this->targetDirectory); $ftp->mkDirRecursive($this->targetDirectory); } // get files from git if enabled if ($this->gitDiff) { $this->files($this->getGitDiff($ftp)); } // scan and index files in finder $this->printTaskInfo('Scanning files to upload...'); // add discrete files $this->finder->append(new \ArrayIterator($this->files)); // directories first $this->finder->sortByType(); // display summary before deploying $this->printTaskInfo(sprintf('Deploying %d files to "%s://%s@%s%s"...', $this->finder->count(), $this->useSSL ? 'ftps' : 'ftp', $this->user, $this->host, $this->targetDirectory)); // upload each file, starting with directories foreach ($this->finder as $file) { $this->upload($ftp, $file); } // close the connection $ftp->close(); } catch (\FtpException $e) { return Result::error($this, 'Error: ' . $e->getMessage()); } // success! return Result::success($this, 'All files deployed.'); }