本文整理汇总了PHP中Ftp::chdir方法的典型用法代码示例。如果您正苦于以下问题:PHP Ftp::chdir方法的具体用法?PHP Ftp::chdir怎么用?PHP Ftp::chdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ftp
的用法示例。
在下文中一共展示了Ftp::chdir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fn_copy_by_ftp
/**
* Copies files using FTP access
*
* @param string $source Absolute path (non-ftp) to source dir/file
* @param string $destination Absolute path (non-ftp) to destination dir/file
* @param array $ftp_access
* array(
* 'hostname',
* 'username',
* 'password',
* 'directory'
* )
* @return bool true if all files were copied or (string) Error message
*/
function fn_copy_by_ftp($source, $destination, $ftp_access)
{
try {
$ftp = new Ftp();
$ftp->connect($ftp_access['hostname']);
$ftp->login($ftp_access['username'], $ftp_access['password']);
$ftp->chdir($ftp_access['directory']);
$files = $ftp->nlist('');
if (!empty($files) && in_array('config.php', $files)) {
$ftp_destination = str_replace(Registry::get('config.dir.root'), '', $destination);
if (is_file($source)) {
// File
try {
$file = ltrim($ftp_destination, '/');
$ftp->put($file, $source, FTP_BINARY);
} catch (FtpException $e) {
throw new FtpException('ftp_access_denied' . ':' . $e->getMessage());
}
} else {
// Dir
$ftp->chdir($ftp_access['directory'] . $ftp_destination);
$struct = fn_get_dir_contents($source, false, true, '', '', true);
foreach ($struct as $file) {
$dir = dirname($file);
if (!$ftp->isDir($dir)) {
try {
$ftp->mkDirRecursive($dir);
} catch (FtpException $e) {
throw new FtpException('ftp_access_denied' . ':' . $e->getMessage());
}
}
try {
$ftp->put($file, $source . $file, FTP_BINARY);
} catch (FtpException $e) {
throw new FtpException('ftp_access_denied' . ':' . $e->getMessage());
}
}
}
return true;
} else {
throw new FtpException('ftp_directory_is_incorrect');
}
} catch (FtpException $e) {
return __('invalid_ftp_access') . ': ' . $e->getMessage();
}
return false;
}
示例2: writeGitCommit
/**
* Writes the current Git commit ID to the remote site.
*
* @param \Ftp $ftp An active FTP connection.
*/
protected function writeGitCommit(\Ftp $ftp)
{
$ftp->chdir($this->targetDirectory);
// get the current commit hash
$result = (new ExecTask('git'))->arg('rev-parse')->arg('HEAD')->run();
// write the commit hash to the meta file
$stream = fopen('data://text/plain,' . trim($result->getMessage()), 'r');
$ftp->fput('.git-commit', $stream, FTP_ASCII);
}