[jcifs] Accessing a local file using SmbFile

Allen, Michael B (RSCH) Michael_B_Allen at ml.com
Wed Feb 26 15:28:16 EST 2003

> -----Original Message-----
> From:	Agnes Chin [SMTP:agnes at elixirtech.com]
> Sent:	Tuesday, February 25, 2003 11:23 PM
> To:	jcifs at lists.samba.org
> Subject:	[jcifs] Accessing a local file using SmbFile
> 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.
	No problem.

>   I 
> find that I can't do this:
>     SmbFile test = new 
> SmbFile("smb://testdomain.com.sg;admin:adminpswd@"); 
> <-- on AIX machine
	Is your NT domain really 'testdomain.com.sg'? Also you do not specify a share
	which will definately be a problem but it should not give you "Connection refused".

> 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", "" );
>             File test = new File("/home/train6/ac/testLocal.text");
>             FileOutputStream out = new FileOutputStream( test );
>             SmbFileInputStream in = new SmbFileInputStream(
>                 "smb://Agnes:agnespswd@" );
>             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?
	Why is it primitive? You should use a buffer though or it will be quite slow. And
	you can reduce this a little to
	new FileOutputStream("/home/train6/ac/test/testLocal.text").

> 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 
	SmbFileOutputStream and SmbFileInputStreams extend OutputStream and
	InputStream so you can do this:

	BufferedReader br =
	      new BufferedReader( new InputStreamReader( new SmbFileInputStream( url )));
	String line = br.readLine();

> 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.
	Not necessary. See the examples like Get.java.

> 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.
	Just keep trying. Eventually you'll figure it out.

> Thanks!
> Agnes

More information about the jcifs mailing list