check if a directory exists or not

@return FTPCLient
@throws PageException
@throws IOException
490734
private AFTPClient actionExistsDir() throws PageException, IOException {
	required("directory", directory);

	AFTPClient client = getClient();
	boolean res = existsDir(client, directory);
	Struct cfftp = writeCfftp(client);

	cfftp.setEL(RETURN_VALUE, Caster.toBoolean(res));
	cfftp.setEL(SUCCEEDED, Boolean.TRUE);

	stoponerror = false;
	return client;
    }
1255129
public boolean exists(Path filename) throws IOException {
    try {
      return getMfs().listFiles(filename, true).hasNext();
    } catch (FileNotFoundException e) {
      return false;
    }
  }
1053789
private void mkDir(String dir) throws Exception {
        Session session = getSession();
        session.connect();
        Channel channel = session.openChannel("sftp");
        channel.connect();

        ChannelSftp c = (ChannelSftp) channel;
        if (!fileExists(dir, c))
            c.mkdir(dir);
        c.exit();
        session.disconnect();
    }
926899
public function isDirectory()
    {
        clearstatcache();
        $fs = FileSystem::getFileSystem();
        if ($fs->checkAccess($this) !== true) {
            throw new IOException("No read access to " . $this->path);
        }

        return @is_dir($this->path) && !@is_link($this->path);
    }
1173289
public function sitePageExists(
        SiteEntity $site,
        $pageName,
        $pageType
    ) {
        try {
            $page = $this->getPageByName(
                $site,
                $pageName,
                $pageType
            );
        } catch (\Exception $e) {
            $page = null;
        }

        return !empty($page);
    }
996213
private AFTPClient actionRemoveDir() throws IOException, PageException {
	required("directory", directory);

	AFTPClient client = getClient();
	if (recursive) {
	    removeRecursive(client, directory, FTPFile.DIRECTORY_TYPE);
	}
	else client.removeDirectory(directory);

	writeCfftp(client);
	return client;
    }
1327333
def exists(self, filepath):
        """"""
        if self.is_ssh(filepath):
            self._check_ftp()
            remotepath = self._get_remote(filepath)
            try:
                self.ftp.stat(remotepath)
            except IOError as e:
                if e.errno == errno.ENOENT:
                    return False
            else:
                return True
        else:
            return os.path.exists(filepath)
337194
private AFTPClient actionExists() throws PageException, IOException {
	required("item", item);

	AFTPClient client = getClient();
	FTPFile file = existsFile(client, item, false);
	Struct cfftp = writeCfftp(client);

	cfftp.setEL(RETURN_VALUE, Caster.toBoolean(file != null));
	cfftp.setEL(SUCCEEDED, Boolean.TRUE);

	return client;
    }
1286705
public function exists()
    {
        clearstatcache();

        if (is_link($this->path)) {
            return true;
        } else {
            if ($this->isDirectory()) {
                return true;
            } else {
                return @file_exists($this->path) || is_link($this->path);
            }
        }
    }
1266460
private AFTPClient actionGetFile() throws PageException, IOException {
	required("remotefile", remotefile);
	required("localfile", localfile);

	AFTPClient client = getClient();
	Resource local = ResourceUtil.toResourceExistingParent(pageContext, localfile);// new File(localfile);
	pageContext.getConfig().getSecurityManager().checkFileLocation(local);
	if (failifexists && local.exists()) throw new ApplicationException("File [" + local + "] already exist, if you want to overwrite, set attribute failIfExists to false");
	OutputStream fos = null;
	client.setFileType(getType(local));
	boolean success = false;
	try {
	    fos = IOUtil.toBufferedOutputStream(local.getOutputStream());
	    success = client.retrieveFile(remotefile, fos);
	}
	finally {
	    IOUtil.closeEL(fos);
	    if (!success) local.delete();
	}
	writeCfftp(client);

	return client;
    }
467735
private AFTPClient actionClose() throws PageException {
	FTPConnection conn = _createConnection();
	AFTPClient client = pool.remove(conn);

	Struct cfftp = writeCfftp(client);
	cfftp.setEL("succeeded", Caster.toBoolean(client != null));
	return client;
    }
791536
public boolean exists() throws APIException {
        HttpResponse response = client.head(getUrl());
        int status = response.getStatusLine().getStatusCode();
        if(status != 200 && status != 404) {
            throw APIException.fromHttpResponse(response);
        }
        return (200 == status);
    }
414175
private AFTPClient actionRename() throws PageException, IOException {
	required("existing", existing);
	required("new", _new);

	AFTPClient client = getClient();
	client.rename(existing, _new);
	writeCfftp(client);

	return client;
    }
1044066
public function fileExists()
    {
        $this->filenameIsValide($this->name);

        return file_exists($this->getPath()) || is_dir($this->base_dir."/".$this->name);
    }
1312864
protected boolean isDirectory(String remoteFilePath) throws IOException {
        if (!ftpClient.changeWorkingDirectory(remoteFilePath)) { // not a directory or not accessible

            switch (ftpClient.listFiles(remoteFilePath).length) {
                case 0:
                    throw new CitrusRuntimeException("Remote file path does not exist or is not accessible: " + remoteFilePath);
                case 1:
                    return false;
                default:
                    throw new CitrusRuntimeException("Unexpected file type result for file path: " + remoteFilePath);
            }
        } else {
            return true;
        }
    }
1278940
public function hasDirectory()
    {
        if (!is_dir($this->getPath()) && !mkdir($this->getPath(), 0775, true)) {
            throw new InvalidCacheDirectoryException('Unable to create cache directory ');
        } elseif (
            !is_readable($this->getPath()) ||
            !is_writable($this->getPath())
        ) {
            if (!chmod($this->getPath(), 0775)) {
                throw new InvalidCacheDirectoryException(
                    'Cache Path Error '.$this->getPath().' directory must be writable'
                );
            }
        }

        return true;
    }
152847
public function read() {
		if (!$this->exists()) {
			throw new FileException(sprintf('File does not exist: %s', $this->getFilename()));
		}

		if (!$this->isReadable()) {
			throw new FileException(sprintf('You don\'t have permissions to access %s file', $this->getFilename()));
		}

		return file_get_contents($this->pathname);
	}