本文整理汇总了PHP中FileUtil::ftpChroot方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::ftpChroot方法的具体用法?PHP FileUtil::ftpChroot怎么用?PHP FileUtil::ftpChroot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::ftpChroot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ftpInit
/**
* 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: testFtpStripChroot
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';
}