/**
  * @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);
     }
 }
 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;
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 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;
 }
Example #5
0
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("..");
}
Example #6
0
 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 [];
     }
 }
Example #7
0
 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;
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 /**
  * 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;
         }
     }
 }
Example #10
0
 /**
  * 获取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;
 }
Example #11
0
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;
}
 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);
 }
Example #13
0
 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;
 }
Example #14
0
 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;
 }
Example #15
0
 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;
 }
Example #16
0
	function exists($path){
		$nlist = ftp_nlist($this->ftp, $path);
		
		if (!is_array($nlist)){
			return false;
		}
		
		return true;
	}
 /**
  * Get the directories / files list on the current working directory
  *
  * @throws \Exception If files cannot be listed
  *
  * @return array|\string[] The list of directories / files contained in the current working directory
  */
 public function listFiles() : array
 {
     ftp_pasv($this->resource, true);
     $list = @ftp_nlist($this->resource, ".");
     if ($list === false) {
         throw new \Exception('Cannot list files from "' . ftp_pwd($this->resource) . '"');
     }
     return $list;
 }
Example #18
0
 public static function CheckDir($dirname, $conn)
 {
     $origin = ftp_pwd($conn);
     if (@ftp_chdir($conn, $dirname)) {
         ftp_chdir($conn, $origin);
         return ftp_nlist($conn, $dirname);
     }
     return false;
 }
Example #19
0
 public function Ftp_recursivo_descarga_listado_archivos($ftpConnection, $path)
 {
     $contents = ftp_nlist($ftpConnection, $path);
     foreach ($contents as $currentFile) {
         $archivos = ftp_nlist($ftpConnection, $currentFile);
         foreach ($archivos as $archivo) {
             $this->descargar_archivos($archivo, $ftpConnection);
         }
     }
 }
Example #20
0
 protected function ftpFileList($path)
 {
     $result;
     $conn_id = ftp_connect(FTP_SERVER);
     $login_result = ftp_login($conn_id, FTP_USER_NAME, FTP_USER_PASS);
     $result = ftp_nlist($conn_id, $path);
     // 接続を閉じる
     ftp_close($conn_id);
     return $result;
 }
Example #21
0
 public function getBouquets($folderName)
 {
     // TODO delete old files
     $files = ftp_nlist($this->_ftpStream, '/etc/enigma2/');
     foreach ($files as $fn) {
         if (pathinfo($fn, PATHINFO_EXTENSION) == 'tv') {
             $target = $folderName . DIRECTORY_SEPARATOR . pathinfo($fn, PATHINFO_BASENAME);
             ftp_get($this->_ftpStream, $target, $fn, FTP_ASCII);
         }
     }
 }
Example #22
0
 function get_filelist($remote_dir)
 {
     @ftp_pasv($this->ftpc, true);
     $fileList = @ftp_nlist($this->ftpc, $remote_dir);
     if (!$fileList) {
         return false;
     } else {
         //ftp_chmod($this->ftpc, 0777, $remote); (php5 only)
         return $fileList;
     }
 }
function ftp_rdel($handle, $path)
{
    if (@ftp_delete($handle, $path) === false) {
        if ($children = @ftp_nlist($handle, $path)) {
            foreach ($children as $p) {
                ftp_rdel($handle, $p);
            }
        }
        @ftp_rmdir($handle, $path);
    }
}
Example #24
0
 /**
  * Get directory listing
  *
  * @param string $directory
  * @param string $parameters
  * @return array
  */
 public function getDirListing($directory = '.', $parameters = null)
 {
     if ($parameters) {
         $directory = $parameters . '  ' . $directory;
     }
     try {
         $contentsArray = ftp_nlist($this->connectionId, $directory);
         return $contentsArray;
     } catch (\Exception $e) {
         return false;
     }
 }
Example #25
0
 public function ls($path = null)
 {
     if (!$this->isReady()) {
         return false;
     }
     try {
         $result = ftp_nlist($this->connection, $path);
     } catch (ErrorException $e) {
         $this->setLastError($e->getMessage());
         $result = false;
     }
     return $result;
 }
Example #26
0
function deleteDirUndFiles($conn_id, $pfad)
{
    $return = @ftp_chdir($conn_id, $pfad);
    $file_list = ftp_nlist($conn_id, "");
    foreach ($file_list as $file) {
        if ($file == "." || $file == "..") {
            //echo "nix";
        } else {
            $return = @ftp_delete($conn_id, $pfad . $file);
        }
    }
    $return = @ftp_rmdir($conn_id, $pfad);
}
Example #27
0
function mappa_torles($mappa, $hova, $id)
{
    if (!(ftp_rmdir($id, "{$hova}/{$mappa}") || ftp_delete($id, "{$hova}/{$mappa}"))) {
        $list = ftp_nlist($id, "{$hova}/{$mappa}");
        if (!empty($list)) {
            foreach ($list as $ezeket) {
                mappa_torles($ezeket, "", $id);
            }
        }
    }
    ftp_rmdir($id, "{$hova}/{$mappa}");
    return header("Location:{$PHP_SELF}?mit=" . urlencode($hova));
}
Example #28
0
 public function removeDir($ftp_folder, $path, $ftp)
 {
     $directories = explode('/', $path);
     foreach ($directories as $directory) {
         $files = ftp_nlist($ftp, $ftp_folder . $path);
         if (count($files) > 2) {
             break;
         }
         if (count($files) == 2) {
             ftp_rmdir($ftp, $ftp_folder . $path);
             str_replace('/' . $directory, '', $path);
         }
     }
 }
Example #29
0
 protected function getFileList($connection, $path) {
     @ftp_chdir($connection, $path);
     $list = ftp_nlist($connection, ".");
     $files = array();
     if ($list) {
         foreach ($list as $filename) {
             $fullpath = strlen($path) < 1 ? $filename : $path . "/" . $filename;
             $size = ftp_size($connection, $filename);
             $files[] = new CloudFile($filename, $fullpath, $size < 0, $size, $this->getName());
         }
     }
     ftp_close($connection);
     return $files;
 }
Example #30
0
 public static function getRadarTransparencies($radar_code, $image_radius_code)
 {
     $radar_string = self::getBoMRadarString($radar_code, $image_radius_code);
     $conn_id = ftp_connect("ftp2.bom.gov.au");
     ftp_login($conn_id, "anonymous", "guest");
     $contents = ftp_nlist($conn_id, '/anon/gen/radar/');
     $matches = preg_grep("/" . $radar_string . ".T/", $contents);
     $web_filenames = [];
     foreach ($matches as $match) {
         $web_filenames[] = "ftp://ftp2.bom.gov.au/{$match}";
     }
     ftp_close($conn_id);
     return $web_filenames;
 }