[jcifs] Accessing a local file using SmbFile

Agnes Chin agnes at elixirtech.com
Wed Feb 26 15:23:09 EST 2003


Hi!

I'm exploring using jcifs in my application, and have encountered some 
issues.

My application is running on an AIX machine (for certain reasons, I'm 
not allowed to install Samba on this machine), and I need to read/write 
to files on a Windows machine.  Particularly, I would need to copy a 
file from my Windows shared directory to my local directory on AIX.  I 
find that I can't do this:

    SmbFile test = new 
SmbFile("smb://testdomain.com.sg;admin:adminpswd@192.168.1.100/testLocal.txt"); 
<-- on AIX machine

Got a "Connection Refused" exception.  Can I do this in the first place??

So, I have to stream the data down, like this:

            jcifs.Config.setProperty( "wins", "192.168.1.105" );

            File test = new File("/home/train6/ac/testLocal.text");
            FileOutputStream out = new FileOutputStream( test );
            SmbFileInputStream in = new SmbFileInputStream(
                "smb://Agnes:agnespswd@192.168.1.105/aaa/testing.txt" );
            int n;
            while(( n = in.read()) > 0 )
            {
                out.write(n);
            }

I find this quite primitive, so would like to know if there's a more 
direct way to do this?

Actually, it all started with me requiring to read in and then process 
the contents of an SmbFile line by line, but found that there isn't a 
corresponding Reader/Writer in the jcifs APIs. Therefore, I resorted to 
duplicating a copy of the file on my local AIX machine, then use 
FileReader/FileWriter to process the file line by line, then make the 
neccesary changes to this local file, and then stream it out again to 
Windows machine.

Excuse my ignorance, as I'm new to Unix, Samba and Java, but would 
really appreciate if there's a better solution than what I'm doing.

Thanks!
Agnes




More information about the jcifs mailing list