当前位置: 首页>>代码示例>>PHP>>正文


PHP Ftp::mkDirRecursive方法代码示例

本文整理汇总了PHP中Ftp::mkDirRecursive方法的典型用法代码示例。如果您正苦于以下问题:PHP Ftp::mkDirRecursive方法的具体用法?PHP Ftp::mkDirRecursive怎么用?PHP Ftp::mkDirRecursive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ftp的用法示例。


在下文中一共展示了Ftp::mkDirRecursive方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 /**
  * @param DatabaseBackupFile $file
  * @return ResultObject[]
  */
 public function process(DatabaseBackupFile $file)
 {
     $d = $file->getBackupDate();
     $results = [];
     foreach ($this->uploadsCredentials as $credentials) {
         $result = new ResultObject();
         // empty ResultObject means all is OK
         $backupPath = $credentials['path'] . '/' . $d->format('Y') . '/' . $d->format('F');
         $entireFilePath = $backupPath . '/' . $file->getFileName();
         try {
             $ftp = new \Ftp();
             $ftp->connect($credentials['host']);
             $ftp->login($credentials['username'], $credentials['password']);
             if (!$ftp->fileExists($backupPath)) {
                 $ftp->mkDirRecursive($backupPath);
             }
             $ftp->put($entireFilePath, $file->getFilePath(), FTP_BINARY);
             $ftp->close();
         } catch (\FtpException $e) {
             $this->logger->addCritical(sprintf('Uploading backup file\'s failed. %s', $e));
             $result->addError('Zálohu se nepodařilo nahrát na: ' . $credentials['host'], 'error');
         }
         $results[] = $result;
     }
     return $results;
 }
开发者ID:blitzik,项目名称:vycetky-doctrine,代码行数:30,代码来源:DatabaseBackupFileHandler.php

示例2: uploadFiles

 /**
  * Uploades files.
  * @return void
  */
 private function uploadFiles(array $files)
 {
     $root = $this->ftp->pwd();
     $root = $root === '/' ? '' : $root;
     $prevDir = NULL;
     $toRename = array();
     foreach ($files as $num => $file) {
         $remoteFile = $root . $file;
         $remoteDir = dirname($remoteFile);
         if ($remoteDir !== $prevDir) {
             $prevDir = $remoteDir;
             if (trim($remoteDir, '\\/') !== '' && !$this->ftp->isDir($remoteDir)) {
                 $this->ftp->mkDirRecursive($remoteDir);
             }
         }
         if (substr($remoteFile, -1) === '/') {
             // is dir?
             continue;
         }
         $localFile = $this->preprocess($orig = ".{$file}");
         if (realpath($orig) !== $localFile) {
             $file .= ' (filters was applied)';
         }
         $toRename[] = $remoteFile;
         $size = filesize($localFile);
         $retry = self::RETRIES;
         upload:
         $blocks = 0;
         do {
             $this->writeProgress($num + 1, count($files), $file, min(round($blocks * self::BLOCK_SIZE / max($size, 1)), 100));
             try {
                 $ret = $blocks === 0 ? $this->ftp->nbPut($remoteFile . self::TEMPORARY_SUFFIX, $localFile, Ftp::BINARY) : $this->ftp->nbContinue();
                 // Ftp::AUTORESUME
             } catch (FtpException $e) {
                 $this->ftp->reconnect();
                 if (--$retry) {
                     goto upload;
                 }
                 throw new Exception("Cannot upload file {$file}, number of retries exceeded.");
             }
             $blocks++;
         } while ($ret === Ftp::MOREDATA);
         $this->writeProgress($num + 1, count($files), $file);
     }
     foreach ($toRename as $num => $file) {
         $this->writeProgress($num + 1, count($toRename), "Renaming {$file}");
         $this->ftp->tryDelete($file);
         $this->ftp->rename($file . self::TEMPORARY_SUFFIX, $file);
         // TODO: zachovat permissions
     }
 }
开发者ID:ondrs,项目名称:ftp-deployment,代码行数:55,代码来源:Deployment.php

示例3: 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;
}
开发者ID:heg-arc-ne,项目名称:cscart,代码行数:61,代码来源:fn.fs.php

示例4: run

 /**
  * Runs the FTP deploy task.
  *
  * @return Result The result of the task.
  */
 public function run()
 {
     $ftp = new \Ftp();
     // connect to the server
     try {
         if ($this->useSSL) {
             $ftp->sslConnect($this->host);
         } else {
             $ftp->connect($this->host);
         }
         $ftp->login($this->user, $this->password);
         // create the target directory if it does not exist
         $ftp->chdir('/');
         if (!$ftp->fileExists($this->targetDirectory)) {
             $this->printTaskInfo('Creating directory: ' . $this->targetDirectory);
             $ftp->mkDirRecursive($this->targetDirectory);
         }
         // get files from git if enabled
         if ($this->gitDiff) {
             $this->files($this->getGitDiff($ftp));
         }
         // scan and index files in finder
         $this->printTaskInfo('Scanning files to upload...');
         // add discrete files
         $this->finder->append(new \ArrayIterator($this->files));
         // directories first
         $this->finder->sortByType();
         // display summary before deploying
         $this->printTaskInfo(sprintf('Deploying %d files to "%s://%s@%s%s"...', $this->finder->count(), $this->useSSL ? 'ftps' : 'ftp', $this->user, $this->host, $this->targetDirectory));
         // upload each file, starting with directories
         foreach ($this->finder as $file) {
             $this->upload($ftp, $file);
         }
         // close the connection
         $ftp->close();
     } catch (\FtpException $e) {
         return Result::error($this, 'Error: ' . $e->getMessage());
     }
     // success!
     return Result::success($this, 'All files deployed.');
 }
开发者ID:coderstephen,项目名称:robo-ftp,代码行数:46,代码来源:FtpDeployTask.php


注:本文中的Ftp::mkDirRecursive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。