Пример #1
0
 /**
  * Initializes the FTP functionality. This connects to
  * the FTP server, logs in, and sets PASV mode.
  * Optionally, you can specify the chroot directory and a directory to
  * change to, e.g.: the web root or the test directory. This is recommended
  * if working with relative paths.
  * @param String $host The FTP server to connect to
  * @param String $user The FTP user.
  * @param String $pass Specified FTP user's password.
  * @param String $dir Initial directory to change to, or null by default
  * to disable.
  * @param String $chroot The chosen chroot directory for the user.
  */
 public static function ftpInit($host, $user, $pass, $dir = null, $chroot = null)
 {
     if (!(self::$_ftpStream = ftp_connect($host))) {
         throw new Exception("The updater is unable to connect to {$host}. Please check your FTP connection settings.", self::ERR_FTPOPER);
     }
     if (!@ftp_login(self::$_ftpStream, $user, $pass)) {
         throw new Exception("Unable to login as user {$user}", self::ERR_FTPOPER);
     }
     ftp_pasv(self::$_ftpStream, true);
     if ($chroot !== null) {
         self::$ftpChroot = $chroot;
     }
     if ($dir !== null) {
         self::cdftp($dir);
     }
     self::$fileOper = "ftp";
 }
Пример #2
0
 public function testFtpStripChroot()
 {
     $absolute = "/home/users/testuser/some/directory";
     $chrootDir = "/home/users/testuser";
     $chrootDirTrailingSlash = "/home/users/testuser/";
     $absoluteWin = 'C:\\Inetpub\\Ftproot\\LocalUser\\testuser\\some\\test\\file.txt';
     $winChroot = "C:\\Inetpub\\Ftproot\\LocalUser\\testuser";
     $relative = "../test/dir";
     FileUtil::$fileOper = 'ftp';
     FileUtil::$ftpChroot = $chrootDir;
     $this->assertEquals("/some/directory", FileUtil::ftpStripChroot($absolute));
     $this->assertEquals($relative, FileUtil::ftpStripChroot($relative));
     FileUtil::$ftpChroot = $chrootDirTrailingSlash;
     $this->assertEquals("/some/directory", FileUtil::ftpStripChroot($absolute));
     FileUtil::$ftpChroot = $winChroot;
     $this->assertEquals("\\some\\test\\file.txt", FileUtil::ftpStripChroot($absoluteWin));
     FileUtil::$fileOper = 'php';
 }