Creating directory access servers

You use the CREATE SERVER statement or Create Directory Access Server Wizard in Sybase Central to create a directory access server.

When you create a directory access server, you can control the number of subdirectories that can be accessed and whether the directory access server can be used to modify existing files.

The following steps are required to set up a directory access server:

  1. Create a remote server for the directory (requires DBA authority).
  2. Create external logins for the database users who can use the directory access server (requires DBA authority).
  3. Create proxy tables to access the directories on the computer (requires RESOURCE authority).

To create and configure a directory access server (Sybase Central)

  1. Connect to the database as a user with DBA authority.

  2. In the left pane, double-click Directory Access Servers.

  3. From the File menu, choose New » Directory Access Server.

    The Create Directory Access Server Wizard appears.

  4. Follow the instructions in the wizard.

To create and configure a directory access server (SQL)

  1. Connect to the host database as a user with DBA authority.

  2. Create a remote server using the CREATE SERVER statement.

    For example:

    CREATE SERVER my_dir_tree
    CLASS 'directory'
    USING 'root=c:\Program Files';
  3. Create an external login using the CREATE EXTERNLOGIN statement.

    For example:

    CREATE EXTERNLOGIN DBA TO my_dir_tree;
  4. Create a proxy table for the directory using the CREATE EXISTING TABLE statement.

    For example:

    CREATE EXISTING TABLE my_program_files AT 'my_dir_tree;;;.';

    In this example, my_program_files is the name of the directory, and my_dir_tree is the name of the directory access server.

Example

The following statements create a new directory access server named directoryserver3 that can be used to access up to three levels of subdirectories, create an external login to the directory access server for the DBA user, and create a proxy table named diskdir3.

CREATE SERVER directoryserver3
CLASS 'DIRECTORY'
USING 'ROOT=c:\mydir;SUBDIRS=3';
CREATE EXTERNLOGIN DBA TO directoryserver3;
CREATE EXISTING TABLE diskdir3 AT 'directoryserver3;;;.';

Using the sp_remote_tables system procedure, you can see all the subdirectories located in c:\mydir on the computer running the database server:

CALL sp_remote_tables( 'directoryserver3' );

Using the following SELECT statement, you can view the contents of the file c:\mydir\myfile.txt:

SELECT contents
FROM diskdir3
WHERE file_name = 'myfile.txt';

Alternatively, you can select data from the directories:

-- Get the list of directories in this disk directory tree.
SELECT permissions, file_name, size
FROM diskdir3
WHERE PERMISSIONS LIKE 'd%';
-- Get the list of files.
SELECT permissions, file_name, size
FROM diskdir3
WHERE PERMISSIONS NOT LIKE 'd%';
See also