Sync Windows CIFS Share File Listing with Database Table
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.