本文整理汇总了PHP中ftp_nlist函数的典型用法代码示例。如果您正苦于以下问题:PHP ftp_nlist函数的具体用法?PHP ftp_nlist怎么用?PHP ftp_nlist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ftp_nlist函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clean
/**
* @param string $file
*/
private function clean($file)
{
if (ftp_size($this->connection, $file) == -1) {
$result = ftp_nlist($this->connection, $file);
foreach ($result as $childFile) {
$this->clean($childFile);
}
ftp_rmdir($this->connection, $file);
} else {
ftp_delete($this->connection, $file);
}
}
示例2: getDirListing
function getDirListing($directory = '.', $parameters = '-a')
{
// get contents of the current directory
//$contentsArray = ftp_nlist($this->connectionId, $parameters . ' ' . $directory);
$contentsArray = ftp_nlist($this->connectionId, $directory);
return $contentsArray;
}
示例3: parseRawList
/**
* @todo create class instead of indexed keys array
*/
protected function parseRawList($dir)
{
$items = array();
if (!($list = ftp_nlist($this->connection, $dir))) {
return false;
}
if (!($rawList = ftp_rawlist($this->connection, $dir))) {
return false;
}
if (count($list) == count($rawList)) {
foreach ($rawList as $index => $child) {
$item = array();
$chunks = preg_split("/\\s+/", $child);
list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'], $item['month'], $item['day'], $item['time']) = $chunks;
$item['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file';
$item['name'] = $list[$index];
$items[] = $item;
}
}
return $items;
foreach ($rawList as $child) {
$chunks = preg_split("/\\s+/", $child);
list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'], $item['month'], $item['day'], $item['time']) = $chunks;
$item['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file';
array_splice($chunks, 0, 8);
$items[implode(" ", $chunks)] = $item;
}
return $items;
}
示例4: GetFTPRoot
static function GetFTPRoot($conn_id, $testDir)
{
$ftp_root = false;
//attempt to find the ftp_root
$testDir = $testDir . '/';
$array = ftp_nlist($conn_id, '.');
if (!$array) {
return false;
}
$possible = array();
foreach ($array as $file) {
if ($file[0] == '.') {
continue;
}
//is the $file within the $testDir.. not the best test..
$pos = strpos($testDir, '/' . $file . '/');
if ($pos === false) {
continue;
}
$possible[] = substr($testDir, $pos);
}
$possible[] = '/';
//test this too
foreach ($possible as $file) {
if (gpftp::TestFTPDir($conn_id, $file, $testDir)) {
$ftp_root = $file;
break;
}
}
return $ftp_root;
}
示例5: ftp_sync
function ftp_sync($dir)
{
global $conn_id;
if ($dir != ".") {
if (ftp_chdir($conn_id, $dir) == false) {
echo "Change Dir Failed: {$dir}<BR>\r\n";
return;
}
if (!is_dir($dir)) {
mkdir($dir);
}
chdir($dir);
}
$contents = ftp_nlist($conn_id, ".");
foreach ($contents as $file) {
if ($file == '.' || $file == '..') {
continue;
}
if (@ftp_chdir($conn_id, $file)) {
ftp_chdir($conn_id, "..");
ftp_sync($file);
} else {
ftp_get($conn_id, $file, $file, FTP_BINARY);
}
}
ftp_chdir($conn_id, "..");
chdir("..");
}
示例6: files
public function files(string $path, string $extension = NULL) : array
{
$list = ftp_nlist($this->connect, $path);
if (!empty($list)) {
foreach ($list as $file) {
if ($file !== '.' && $file !== '..') {
if (!empty($extension) && $extension !== 'dir') {
if (extension($file) === $extension) {
$files[] = $file;
}
} else {
if ($extension === 'dir') {
$extens = extension($file);
if (empty($extens)) {
$files[] = $file;
}
} else {
$files[] = $file;
}
}
}
}
}
if (!empty($files)) {
return $files;
} else {
return [];
}
}
示例7: getFromFTP
public function getFromFTP($ftp, $user, $pass, $dir)
{
$connect = ftp_connect($ftp);
$login_result = ftp_login($connect, $user, $pass);
$contents = ftp_nlist($connect, $dir);
return $contents;
}
示例8: fetchFile
/**
* Fetch data file from Itella FTP server
* @param $type Data file type (PCF = localities, BAF = street addresses, POM = zip code changes)
* @returns Temp file name
*/
public function fetchFile($type)
{
//Connect to FTP server
$ftp = ftp_connect($this->host);
if ($ftp === false) {
throw new Exception("Could not connect to '{$this->host}'");
}
if (!ftp_login($ftp, $this->user, $this->password)) {
throw new Exception("Login to '{$this->host}' as '{$this->user}' failed");
}
//Find filename to download
ftp_pasv($ftp, true);
$list = ftp_nlist($ftp, '.');
$file = null;
foreach ($list as $item) {
$parts = explode('_', $item);
if (isset($parts[0]) && strtoupper($parts[0]) == strtoupper($type)) {
$file = $item;
}
}
if ($file == null) {
throw new Exception("'{$type}' file not found");
}
//Download requested data file
$tmpFile = tempnam(sys_get_temp_dir(), 'FinZip_' . $type . '_') . '.zip';
$this->tmpFiles[] = $tmpFile;
$tmp = fopen($tmpFile, 'w');
ftp_pasv($ftp, true);
ftp_fget($ftp, $tmp, $file, FTP_BINARY);
ftp_close($ftp);
fclose($tmp);
//Return the filename of the temporary file
return $tmpFile;
}
示例9: get_file
/**
* Function that retrieves a file from FTP library and compress it if necessary
*
* @param string $file File name to be retrieved from FTP library
* @return boolean
*/
public function get_file($file, $dir = '')
{
if (!defined("LOCATION") || !defined("CODE") || !defined("LIBRARY") || !defined("CACHE_PATH")) {
$this->container->__error("Imposible recuperar el archivo remoto: falta alguna constante por definir");
return false;
}
$cnn = ftp_connect(LOCATION);
$rs = ftp_login($cnn, LIBRARY, CODE);
if ($rs === false) {
$this->container->__error("Imposible conectar a la libreria de funciones!");
}
$dir = $dir == '' ? '' : $dir . DIRECTORY_SEPARATOR;
ftp_chdir($cnn, LIBRARY . DIRECTORY_SEPARATOR . $dir);
if (@ftp_chdir($cnn, $file) !== false) {
if ($this->container->__debug()) {
@mkdir(CACHE_PATH . $dir . $file);
chmod(CACHE_PATH . $dir . $file, 0777);
$dir = $dir == '' ? $file : $dir . $file;
} else {
@mkdir(CACHE_PATH . $dir . md5($file));
chmod(CACHE_PATH . $dir . md5($file), 0777);
$dir = $dir == '' ? $file : $dir . $file;
}
$files = ftp_nlist($cnn, ".");
foreach ($files as $filea) {
$this->get_file($filea, $dir);
}
return true;
} else {
if ($file == '.' || $file == '..') {
return;
}
if ($this->container->__debug()) {
$aux = ftp_get($cnn, CACHE_PATH . $dir . $file, $file, FTP_BINARY);
} else {
$temp = explode(DIRECTORY_SEPARATOR, $dir);
array_walk($temp, function (&$element, $index) {
$element = md5($element);
});
array_pop($temp);
$temp = implode(DIRECTORY_SEPARATOR, $temp) . DIRECTORY_SEPARATOR;
$aux = ftp_get($cnn, CACHE_PATH . $temp . md5($file), $file, FTP_BINARY);
}
if (!$aux) {
ftp_close($cnn);
$this->container->__error("Imposible obtener el archivo para cache: " . $file);
return false;
} else {
ftp_close($cnn);
if ($this->container->__debug()) {
chmod(CACHE_PATH . $dir . $file, 0777);
$this->compress_cache_file($dir . $file);
} else {
chmod(CACHE_PATH . $temp . md5($file), 0777);
$this->compress_cache_file($temp . md5($file));
}
return true;
}
}
}
示例10: getlist
/**
* 获取FTP指定目录列表
*
* @access public
* @param mixed $dir 文件夹
* @return array 返回数组, 内分 [dir] 跟 [file]
*/
public function getlist($dir = '')
{
$dir = !$dir ? $this->dirlink : $dir;
$list = ftp_nlist($this->link, $dir);
if (!$list) {
$this->errormsg = "Can't list this dir";
return FALSE;
} else {
$dirarray = array();
foreach ($list as $value) {
$v = strrchr($value, '/');
if ($v) {
$temp = substr(strrchr($value, '/'), '1');
$path = pathinfo($temp);
if (isset($path['extension']) && $path['extension']) {
$dirarray['file'][] = $temp;
} else {
$dirarray['dir'][] = $temp;
}
} else {
$path = pathinfo($value);
if (isset($path['extension']) && $path['extension']) {
$dirarray['file'][] = $value;
} else {
$dirarray['dir'][] = $value;
}
}
}
}
return $dirarray;
}
示例11: build_content
function build_content($ftp, $dir)
{
$content_array = array();
$dirs_array = array();
$files_array = array();
$files = ftp_nlist($ftp, $dir);
foreach ($files as $filename) {
$filename = explode('/', $filename);
$filename = $filename[count($filename) - 1];
if ($filename == '.' || $filename == '..') {
continue;
}
$fullname = $filename;
if ($dir != '') {
$fullname = $dir . '/' . $fullname;
}
$filename = utf8_encode($filename);
if (ftp_size($ftp, $fullname) == -1) {
$fullname = utf8_encode($fullname);
$dirs_array[] = array('name' => $filename, 'file' => $fullname, 'is_folder' => 'true');
} else {
$fullname = utf8_encode($fullname);
$files_array[] = array('name' => $filename, 'file' => $fullname, 'icon' => get_icon($filename));
}
}
usort($dirs_array, 'cmp');
usort($files_array, 'cmp');
$content_array = array_merge($dirs_array, $files_array);
return $content_array;
}
示例12: actionSynchronization
public function actionSynchronization()
{
if (date('w', time()) == 0 || date('w', time()) == 6) {
return;
}
$transfer_src = ftp_connect('91.197.79.112');
$login_result = ftp_login($transfer_src, 'transfer', 'dnUtd74n');
if (!$login_result) {
return false;
}
ftp_pasv($transfer_src, TRUE);
$files = ftp_nlist($transfer_src, ".");
foreach ($files as $file) {
if (!is_file(Yii::getAlias('@backend/web/') . $this->upload_dir . '/' . $file)) {
$transfer_dst = ftp_connect('37.46.85.148');
$login_result = ftp_login($transfer_dst, 'carakas', 'hokwEw21');
if (!$login_result) {
return false;
}
ftp_pasv($transfer_dst, TRUE);
ftp_get($transfer_src, Yii::getAlias('@backend/web/') . $this->upload_dir . '/' . $file, $file, FTP_ASCII);
ftp_put($transfer_dst, $file, Yii::getAlias('@backend/web/') . $this->upload_dir . '/' . $file, FTP_BINARY);
ftp_close($transfer_dst);
}
}
ftp_close($transfer_src);
}
示例13: getFileList
public function getFileList($dirname)
{
if (($fileList = ftp_nlist($this->ftpStream, Gpf_Paths::INSTALL_DIR)) == false) {
throw new Gpf_Exception($this->_('Directory %s does not exist', Gpf_Paths::INSTALL_DIR));
}
Gpf_Log::debug('Getting files list: ' . print_r($fileList, true));
return $fileList;
}
示例14: getFiles
protected function getFiles($remoteDirectory)
{
$files = ftp_nlist($this->connection, $remoteDirectory);
if ($files === false) {
throw new \Exception('Could not get files from directory ' . $remoteDirectory);
}
return $files;
}
示例15: getDirNames
public function getDirNames($dir)
{
$direcotryContent = array_map('basename', ftp_nlist($this->conn_id, './Filme/' . $dir));
$direcotoryFolders = array_filter($direcotryContent, function ($var) {
return strpos($var, '.') === false;
});
return $direcotoryFolders;
}