예제 #1
0
 /**
  * Download test.
  * @return void
  */
 public function testDownload()
 {
     $ftp = new Ftp();
     // Opens an FTP connection to the specified host
     $ftp->connect('ftp.nettephp.com');
     $ftp->pasv(TRUE);
     // Login with username and password
     $ftp->login('*****@*****.**', 'anonymous');
     // Download file 'README' to local temporary file
     $temp = tmpfile();
     $ftp->fget($temp, 'README', Ftp::ASCII);
     // echo file
     fseek($temp, 0);
     $this->assertEquals("Nette Framework rocks!", stream_get_contents($temp));
 }
예제 #2
0
 /**
  * Gets a list of files to be uploaded based on the difference between HEAD
  * and the commit last deployed.
  *
  * @param \Ftp $ftp An active FTP connection.
  *
  * @return string[] An array of file names to upload.
  */
 protected function getGitDiff(\Ftp $ftp)
 {
     $this->printTaskInfo('Checking remote site for Git info...');
     $ftp->chdir($this->targetDirectory);
     if (in_array('.git-commit', $ftp->nlist('.'))) {
         $tempHandle = fopen('php://temp', 'r+');
         if ($ftp->fget($tempHandle, '.git-commit', FTP_ASCII, 0)) {
             rewind($tempHandle);
             $commitId = stream_get_contents($tempHandle);
             $this->printTaskInfo('Remote site has version ' . $commitId . '.');
             $this->printTaskInfo(' Scanning for changes...');
             $result = $this->taskExec('git')->arg('diff')->arg('--name-only')->arg('--diff-filter=ACMRT')->arg($commitId)->arg('HEAD')->run();
             return preg_split('/[\\r\\n]+/', trim($result->getMessage()));
         }
     }
     $this->printTaskInfo('No Git info found on remote site.');
     $this->printTaskInfo('Adding all files in repo...');
     // No commit saved on remote site; deploy everything in repo
     $result = $this->taskExec('git')->arg('ls-files')->run();
     return preg_split('/[\\r\\n]+/', trim($result->getMessage()));
 }
예제 #3
0
<?php

require_once 'ftp.class.php';
try {
    $ftp = new Ftp();
    // Opens an FTP connection to the specified host
    $ftp->connect('ftp.ed.ac.uk');
    // Login with username and password
    $ftp->login('anonymous', '*****@*****.**');
    // Download file 'README' to local temporary file
    $temp = tmpfile();
    $ftp->fget($temp, 'README', Ftp::ASCII);
    // echo file
    echo '<pre>';
    fseek($temp, 0);
    fpassthru($temp);
} catch (FtpException $e) {
    echo 'Error: ', $e->getMessage();
}