Skip to content

Sync Windows CIFS Share File Listing with Database Table

January 11, 2012

I recently had the need to store a list of file names on a Windows share within an Oracle database table.  This may have been easy if the database ran on Windows, but fortunately it runs on Linux.  To do the sync I wrote a Java application that connects to a Windows share, does a file listing, and then stores the listing in a database table.  To run this, you will need to do the following:

Create Database Table:

CREATE TABLE
    WINDOWS_SHARE_DATA
    (
        SHARE_NAME VARCHAR2(30) NOT NULL,
        DIRECTORY VARCHAR2(30) NOT NULL,
        FILE_NAME VARCHAR2(65) NOT NULL
    )

You will also need:
Java
Jcifs Library
Oracle JDBC Driver

To run the application first set your classpath so that it includes the Jcifs Library and the Oracle JDBC Driver:

export CLASSPATH=.:/classes/jcifs-1.3.17.jar:/classes/ojdbc6.jar

To run the application, do the following:

$JAVA_HOME/bin/java CifsToDB "smb://DOMAIN;USERNAME:PASSWORD@SERVER/SHARE/DIRECTORY/" "jdbc:oracle:thin:USERNAME/PASSWORD//SERVER:PORT/SERIVCENAME"

Download the following class. Rename the file to CifsToDB.class.

CifsToDB Java Class

Advertisement

From → Linux, Oracle, Programming

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.