本文整理汇总了PHP中ftp_cdup函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_cdup函数的具体用法?PHP ftp_cdup怎么用?PHP ftp_cdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftp_cdup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cd
/**
* Change Directory
* @param string $dir
* @return ftp
*
*/
public function cd($dir)
{
$dir = (string) $dir;
$dir === '..' ? ftp_cdup($this->ftp) : ftp_chdir($this->ftp, $dir);
$this->path = $this->pwd();
return $this;
}
示例2: download_file
function download_file($conn, $ftppath, $prjname)
{
$fn = ftp_rawlist($conn, $ftppath);
//列出该目录的文件名(含子目录),存储在数组中
foreach ($fn as $file) {
$b = explode(' ', $file);
$s = sizeof($b);
$file = $b[$s - 1];
if (preg_match('/^[a-zA-Z0-9_]+([a-zA-Z0-9-]*.*)(\\.+)/i', $file)) {
if (!file_exists($prjname . "/" . $file)) {
$fp = fopen($prjname . "/" . $file, "w");
}
if (ftp_get($conn, $prjname . "/" . $file, $ftppath . "/" . $file, FTP_BINARY)) {
echo "<br/>下载" . $prjname . "/" . $file . "成功<br/>";
} else {
echo "<br/>下载" . $prjname . "/" . $file . "失败<br/>";
}
} else {
if (!file_exists($prjname . "/" . $file)) {
echo "新建目录:" . $prjname . "/" . $file . "<br>";
mkdir(iconv("UTF-8", "GBK", $prjname . "/" . $file), 0777, true);
//本地机器上该目录不存在就创建一个
}
if (ftp_chdir($conn, $ftppath . "/" . $file)) {
chdir($prjname . "/" . $file);
}
$this->download_file($conn, $ftppath . "/" . $file, $prjname . "/" . $file);
//递归进入该目录下载文件
}
}
//foreach循环结束
ftp_cdup($conn);
//ftp服务器返回上层目录
chdir(dirname($prjname));
}
示例3: removeDirectoryJailed
/**
* {@inheritdoc}
*/
protected function removeDirectoryJailed($directory)
{
$pwd = ftp_pwd($this->connection);
if (!ftp_chdir($this->connection, $directory)) {
throw new FileTransferException("Unable to change to directory @directory", NULL, array('@directory' => $directory));
}
$list = @ftp_nlist($this->connection, '.');
if (!$list) {
$list = array();
}
foreach ($list as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (@ftp_chdir($this->connection, $item)) {
ftp_cdup($this->connection);
$this->removeDirectory(ftp_pwd($this->connection) . '/' . $item);
} else {
$this->removeFile(ftp_pwd($this->connection) . '/' . $item);
}
}
ftp_chdir($this->connection, $pwd);
if (!ftp_rmdir($this->connection, $directory)) {
throw new FileTransferException("Unable to remove to directory @directory", NULL, array('@directory' => $directory));
}
}
示例4: cdup
function cdup()
{
$this->login();
$isok = ftp_cdup($this->link_id);
if ($isok) {
$this->dir = $this->pwd();
}
return $isok;
}
示例5: copy_file_to_ftp
function copy_file_to_ftp($idhash, $year, $month)
{
global $con;
// Returning to root path
ftp_cdup($con);
ftp_cdup($con);
// Check existing directory of year
navigate_to_dir($year);
// Check existing directory of month
navigate_to_dir($month);
// Copy file
$res = ftp_put($con, '/' . $year . '/' . $month . '/' . $idhash, IMGS_PATH . $idhash, FTP_BINARY);
if (!$res) {
// We in cycle for upload few images - if got error - we'll continue, message only
$err = error_get_last();
printf("Could not upload file %s\r\n%s\r\n", $idhash, $err["message"]);
return false;
}
return true;
}
示例6: dir_mkdirs
/**
* 方法:生成目录
* @path -- 路径
*/
function dir_mkdirs($path)
{
$path_arr = explode('/', $path);
// 取目录数组
$file_name = array_pop($path_arr);
// 弹出文件名
$path_div = count($path_arr);
// 取层数
foreach ($path_arr as $val) {
if (@ftp_chdir($this->conn_id, $val) == FALSE) {
$tmp = @ftp_mkdir($this->conn_id, $val);
if ($tmp == FALSE) {
echo "目录创建失败,请检查权限及路径是否正确!";
exit;
}
@ftp_chdir($this->conn_id, $val);
}
}
for ($i = 1; $i = $path_div; $i++) {
@ftp_cdup($this->conn_id);
}
}
示例7: copyFileViaFtp
function copyFileViaFtp($sourcePath, $destinationPath, $connectionId)
{
$errorMessage = '';
$sourcePath = str_replace(" ", "-", $sourcePath);
$destinationPath = sanitiseFtpPath($destinationPath);
if (@(!ftp_mkdir($connectionId, $destinationPath))) {
$errorMessage .= "&error-ftp-unable-to-create-directory; " . $destinationPath . "\n";
}
@ftp_site($connectionId, 'CHMOD 0777 ' . $destinationPath);
// non-Unix-based servers may respond with "Command not implemented for that parameter" as they don't support chmod, so don't display any errors of this command.
ftp_chdir($connectionId, $destinationPath);
//print $sourcePath.' to '.$destinationPath."<br />";
if (is_dir($sourcePath)) {
chdir($sourcePath);
$handle = opendir('.');
while (($file = readdir($handle)) !== false) {
if ($file != "." && $file != "..") {
if (is_dir($file)) {
$errorMessage .= copyFileViaFtp($sourcePath . DIRECTORY_SEPARATOR . $file, $file, $connectionId);
chdir($sourcePath);
if (!ftp_cdup($connectionId)) {
$errorMessage .= '&error-unable-ftp-cd-up;';
}
} else {
if (substr($file, strlen($file) - 4, 4) != '.zip') {
$fp = fopen($file, 'r');
if (!ftp_fput($connectionId, sanitiseFtpPath($file), $fp, FTP_BINARY)) {
$errorMessage .= '&error-unable-ftp-fput;';
}
@ftp_site($connectionId, 'CHMOD 0755 ' . sanitiseFtpPath($file));
fclose($fp);
}
}
}
}
closedir($handle);
}
return $errorMessage;
}
示例8: ftp_myexec2
function ftp_myexec2($ftp, $list)
{
global $ftp_log, $ftp_error, $lang;
// getting current directory
$root_dir = @ftp_pwd($ftp);
if ($root_dir === false) {
$ftp_log[] = $ftp_error = $lang['xs_ftp_log_nopwd'];
return false;
}
$current_dir = strlen($root_dir) ? $root_dir . '/' : '';
// run commands
for ($i = 0; $i < count($list); $i++) {
$item = $list[$i];
if ($item['command'] == 'mkdir') {
// create new directory
$res = @ftp_mkdir($ftp, $item['dir']);
if (!$res) {
$ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_nomkdir']);
if (empty($item['ignore'])) {
return false;
}
} else {
$ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_mkdir']);
}
} elseif ($item['command'] == 'chdir') {
// change current directory
$res = @ftp_chdir($ftp, $item['dir']);
if (!$res) {
$ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_nochdir']);
if (empty($item['ignore'])) {
return false;
}
} else {
$ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_chdir']);
}
} elseif ($item['command'] == 'cdup') {
// change current directory
$res = @ftp_cdup($ftp);
if (!$res) {
$ftp_log[] = $ftp_error = str_replace('{DIR}', '..', $lang['xs_ftp_log_nochdir']);
if (empty($item['ignore'])) {
return false;
}
} else {
$ftp_log[] = str_replace('{DIR}', '..', $lang['xs_ftp_log_chdir']);
}
} elseif ($item['command'] == 'rmdir') {
// remove directory
$res = @ftp_rmdir($ftp, $item['dir']);
if (!$res) {
$ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_normdir']);
if (empty($item['ignore'])) {
return false;
}
} else {
$ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_rmdir']);
}
} elseif ($item['command'] == 'upload') {
// upload file
$res = @ftp_put($ftp, $current_dir . $item['remote'], $item['local'], FTP_BINARY);
if (!$res) {
$ftp_log[] = $ftp_error = str_replace('{FILE}', $item['remote'], $lang['xs_ftp_log_noupload']);
if (empty($item['ignore'])) {
return false;
}
} else {
$ftp_log[] = str_replace('{FILE}', $item['remote'], $lang['xs_ftp_log_upload']);
}
} elseif ($item['command'] == 'chmod') {
// upload file
$res = @ftp_chmod($ftp, $item['mode'], $current_dir . $item['file']);
if (!$res) {
$ftp_log[] = str_replace('{FILE}', $item['file'], $lang['xs_ftp_log_nochmod']);
if (empty($item['ignore'])) {
return false;
}
} else {
$ftp_log[] = str_replace(array('{FILE}', '{MODE}'), array($item['file'], $item['mode']), $lang['xs_ftp_log_chmod']);
}
} elseif ($item['command'] == 'exec') {
$res = ftp_myexec2($ftp, $item['list']);
if (!$res) {
return false;
}
} elseif ($item['command'] == 'removeall') {
ftp_remove_all($ftp);
} else {
$ftp_log[] = str_replace('{COMMAND}', $item['command'], $lang['xs_ftp_log_invalidcommand']);
if (empty($item['ignore'])) {
return false;
}
}
}
// changing current directory back
$ftp_log[] = str_replace('{DIR}', $root_dir, $lang['xs_ftp_log_chdir2']);
if (!@ftp_chdir($ftp, $root_dir)) {
$ftp_log[] = $ftp_error = str_replace('{DIR}', $root_dir, $lang['xs_ftp_log_nochdir2']);
return false;
}
return true;
//.........这里部分代码省略.........
示例9: chdir
/**
* Change Directory
*
* @param string $dir New directory
* @return @e void
* @throws Exception CHDIR_FAILED
*/
public function chdir($dir)
{
if ($dir == '..') {
$currentDir = @ftp_pwd($this->stream);
$chdir = @ftp_cdup($this->stream);
if ($currentDir === @ftp_pwd($this->stream)) {
$chdir = false;
}
} elseif (substr($dir, 0, 1) !== '/') {
$dir = $this->directory . '/' . $dir;
$chdir = @ftp_chdir($this->stream, $dir);
} else {
$chdir = @ftp_chdir($this->stream, $dir);
}
if (!$chdir) {
throw new Exception('CHDIR_FAILED');
}
$this->directory = @ftp_pwd($this->stream);
}
示例10: parentDir
/**
* Changes to the parent directory on the remote FTP server.
*
* @return boolean
*/
public function parentDir()
{
if ($this->getActive()) {
// Move up!
if (ftp_cdup($this->_connection)) {
return true;
} else {
return false;
}
} else {
throw new CDbException('EFtpComponent is inactive and cannot perform any FTP operations.');
}
}
示例11: test
/**
* Tests FTP server
*
* @param string $error
* @return boolean
*/
function test(&$error)
{
if (!parent::test($error)) {
return false;
}
$rand = md5(time());
$tmp_dir = 'test_dir_' . $rand;
$tmp_file = 'test_file_' . $rand;
$tmp_path = W3TC_CACHE_TMP_DIR . '/' . $tmp_file;
if (!@file_put_contents($tmp_path, $rand)) {
$error = sprintf('Unable to create file: %s.', $tmp_path);
return false;
}
if (!$this->_connect($error)) {
return false;
}
$this->_set_error_handler();
if (!@ftp_mkdir($this->_ftp, $tmp_dir)) {
$error = sprintf('Unable to make directory: %s (%s).', $tmp_dir, $this->_get_last_error());
@unlink($tmp_path);
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if (file_exists($this->_config['docroot'] . '/' . $tmp_dir)) {
$error = sprintf('Test directory was made in your site root, not on separate FTP host or path. Change path or FTP information: %s.', $tmp_dir);
@unlink($tmp_path);
@ftp_rmdir($this->_ftp, $tmp_dir);
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if (!@ftp_chdir($this->_ftp, $tmp_dir)) {
$error = sprintf('Unable to change directory to: %s (%s).', $tmp_dir, $this->_get_last_error());
@unlink($tmp_path);
@ftp_rmdir($this->_ftp, $tmp_dir);
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
if (!@ftp_put($this->_ftp, $tmp_file, $tmp_path, FTP_BINARY)) {
$error = sprintf('Unable to upload file: %s (%s).', $tmp_path, $this->_get_last_error());
@unlink($tmp_path);
@ftp_cdup($this->_ftp);
@ftp_rmdir($this->_ftp, $tmp_dir);
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
@unlink($tmp_path);
if (!@ftp_delete($this->_ftp, $tmp_file)) {
$error = sprintf('Unable to delete file: %s (%s).', $tmp_path, $this->_get_last_error());
@ftp_cdup($this->_ftp);
@ftp_rmdir($this->_ftp, $tmp_dir);
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
@ftp_cdup($this->_ftp);
if (!@ftp_rmdir($this->_ftp, $tmp_dir)) {
$error = sprintf('Unable to remove directory: %s (%s).', $tmp_dir, $this->_get_last_error());
$this->_restore_error_handler();
$this->_disconnect();
return false;
}
$this->_restore_error_handler();
$this->_disconnect();
return true;
}
示例12: mkdir
/**
* 目录生成(支持递归)
*
* @access public
* @param string 目录标识(ftp)
* @return boolean
*/
public function mkdir($path = '', $permissions = NULL)
{
if ($path == '' or !$this->_isconn()) {
return FALSE;
}
if ($path[strlen($path) - 1] != '/') {
$path .= '/';
}
$path_arr = explode('/', $path);
// 取目录数组
$file_name = array_pop($path_arr);
// 弹出文件名
$path_div = count($path_arr);
// 取层数
foreach ($path_arr as $val) {
if (@ftp_chdir($this->conn_id, $val) == FALSE) {
$result = @ftp_mkdir($this->conn_id, $val);
if ($result == FALSE) {
if ($this->debug === TRUE) {
$this->_error("ftp_unable_to_mkdir:dir[" . $path . "]");
}
return FALSE;
}
@ftp_chdir($this->conn_id, $val);
}
}
for ($i = 1; $i <= $path_div; $i++) {
@ftp_cdup($this->conn_id);
}
if (!is_null($permissions)) {
$this->chmod($path, (int) $permissions);
}
return TRUE;
}
示例13: deleteFolder
function deleteFolder($folder, $path)
{
global $conn_id;
global $lang_cant_delete;
global $lang_folder_doesnt_exist;
global $lang_folder_cant_delete;
$isError = 0;
// List contents of folder
if ($path != "/" && $path != "~") {
$folder_path = $path . "/" . $folder;
} else {
if ($_SESSION["win_lin"] == "lin" || $_SESSION["win_lin"] == "mac") {
if ($_SESSION["dir_current"] == "/") {
$folder_path = "/" . $folder;
}
}
if ($_SESSION["dir_current"] == "~") {
$folder_path = "~/" . $folder;
}
if ($_SESSION["win_lin"] == "win") {
$folder_path = "/" . $folder;
}
}
$ftp_rawlist = getFtpRawList($folder_path);
// Go through array of files/folders
if (sizeof($ftp_rawlist) > 0) {
$count = 0;
foreach ($ftp_rawlist as $ff) {
$count++;
// Split up array into values (Lin)
if ($_SESSION["win_lin"] == "lin") {
$ff = preg_split("/[\\s]+/", $ff, 9);
$perms = $ff[0];
$file = $ff[8];
if (getFileType($perms) == "d") {
$isFolder = 1;
} else {
$isFolder = 0;
}
}
// Split up array into values (Mac)
// skip first line
if ($_SESSION["win_lin"] == "mac") {
if ($count == 1) {
continue;
}
$ff = preg_split("/[\\s]+/", $ff, 9);
$perms = $ff[0];
$file = $ff[8];
if (getFileType($perms) == "d") {
$isFolder = 1;
} else {
$isFolder = 0;
}
}
// Split up array into values (Win)
if ($_SESSION["win_lin"] == "win") {
$ff = preg_split("/[\\s]+/", $ff, 4);
$size = $ff[2];
$file = $ff[3];
if ($size == "<DIR>") {
$isFolder = 1;
} else {
$isFolder = 0;
}
}
if ($file != "." && $file != "..") {
// Check for sub folders and then perform this function
if ($isFolder == 1) {
deleteFolder($file, $folder_path);
} else {
// otherwise delete file
$file_path = $folder_path . "/" . $file;
if (!@ftp_delete($conn_id, "" . $file_path . "")) {
if (checkFirstCharTilde($file_path) == 1) {
if (!@ftp_delete($conn_id, "" . replaceTilde($file_path) . "")) {
recordFileError("file", replaceTilde($file_path), $lang_cant_delete);
}
} else {
recordFileError("file", $file_path, $lang_cant_delete);
}
}
}
}
}
}
// Check if file exists
if (checkFileExists("d", $folder, $folder_path) == 1) {
$_SESSION["errors"][] = str_replace("[file]", "<strong>" . tidyFolderPath($folder_path, $folder) . "</strong>", $lang_folder_doesnt_exist);
} else {
// Chage dir up before deleting
ftp_cdup($conn_id);
// Delete the empty folder
if (!@ftp_rmdir($conn_id, "" . $folder_path . "")) {
if (checkFirstCharTilde($folder_path) == 1) {
if (!@ftp_rmdir($conn_id, "" . replaceTilde($folder_path) . "")) {
recordFileError("folder", replaceTilde($folder_path), $lang_folder_cant_delete);
$isError = 1;
}
} else {
//.........这里部分代码省略.........
示例14: ftp_isdir
/**
* Tell if an entry is a FTP directory
*
* @param resource $connect_id Connection handler
* @param string $dir Directory
* @return int 1=directory, 0=not a directory
*/
function ftp_isdir($connect_id, $dir)
{
if (@ftp_chdir($connect_id, $dir)) {
ftp_cdup($connect_id);
return 1;
} else {
return 0;
}
}
示例15: _ftpMkDirR
function _ftpMkDirR($sPath)
{
$sPwd = ftp_pwd($this->_rStream);
$aParts = explode("/", $sPath);
$sPathFull = '';
if ('/' == $sPath[0]) {
$sPathFull = '/';
ftp_chdir($this->_rStream, '/');
}
foreach ($aParts as $sPart) {
if (!$sPart) {
continue;
}
$sPathFull .= $sPart;
if ('..' == $sPart) {
@ftp_cdup($this->_rStream);
} elseif (!@ftp_chdir($this->_rStream, $sPart)) {
if (!@ftp_mkdir($this->_rStream, $sPart)) {
ftp_chdir($this->_rStream, $sPwd);
return false;
}
@ftp_chdir($this->_rStream, $sPart);
}
$sPathFull .= '/';
}
ftp_chdir($this->_rStream, $sPwd);
return true;
}