[jcifs] SmbFileInputStream Problem

Michael B Allen miallen at ioplex.com
Thu Nov 22 08:03:38 GMT 2007


Follow the example programs. In particular SmbSession.logon is not what
you think it's for.

On Thu, 22 Nov 2007 15:11:55 +1000
Matthew.Mortensen at ghd.com.au wrote:

> I have the code below  which seems to get the SMB file without any 
> problem.
> 
> The output is as folows, so you can see it's getting the file as I can get 
> the filesize. 
> 358487.doc exists
> File size -  371200
> Downloading File full -  \\BNE10NAS\Projects\31\20640\WP\358487.doc
> Authentication Failure.
> 
> The problem is when I set the SmbFileInputStream.  I get the following 
> error.  Why would authentication work for the File bu not for the Stream?
> Authentication Failure.
> jcifs.smb.SmbAuthException: Access is denied.
>         at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:503)
>         at jcifs.smb.SmbTransport.send(SmbTransport.java:614)
>         at jcifs.smb.SmbSession.send(SmbSession.java:239)
>         at jcifs.smb.SmbTree.send(SmbTree.java:109)
>         at jcifs.smb.SmbFile.send(SmbFile.java:695)
>         at jcifs.smb.SmbFile.open0(SmbFile.java:887)
>         at jcifs.smb.SmbFile.open(SmbFile.java:904)
>         at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:70)
>         at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:62)
>         at FTPTesting.main(FTPTesting.java:71)
> 
> public class FTPTesting {
>  
>  
>         public static void main(String[] args) {
>  
>                 Config.setProperty("jcifs.smb.client.domain", "xxxx");
>                 Config.setProperty("jcifs.smb.client.username", "xxxx");
>                 Config.setProperty("jcifs.smb.client.password", "xxxx");
>                 Config.setProperty("jcifs.netbios.wins", "xxxx");
> 
>                 FTPClient ftp;
>                 ftp = null;
>                 ftp = new FTPClient();
> 
>       try  { 
> 
>                         String server = "xxxx"; 
>                         String username = "xxxx";
>                         String password = "xxxx"; 
>                         String local;
>                         String target;
> 
>         //AUTHENTICATE HERE
>                   InetAddress ip = InetAddress.getByName("xxxxxxx"); // ip 
> address of your windows controller
>                   UniAddress myDomain = new UniAddress(ip);
>                   NtlmPasswordAuthentication auth = new 
> NtlmPasswordAuthentication("GHDNET", username, password);
>                   SmbSession.logon(myDomain, auth);
>      //AUTH FINISH
> 
>                   local = "smb://BNE10NAS/Projects/31/20640/WP/358487.doc"
> ;
> 
>                   SmbFile f1 = new SmbFile(local,auth);
>                   if( f1.exists() ) {
>                           System.out.println( f1.getName() + " exists" );
>                   } else {
>                           System.out.println( f1.getName() + " does not 
> exist" );
>                   }
> 
>                   System.out.println( "File size -  "+f1.length());
>                   System.out.println( "Downloading File full -  "
> +f1.getUncPath()); 
>  
>                   SmbFileInputStream in = new SmbFileInputStream(f1);
>                   System.out.println("Check stream  - "+in.available()); 
>  
>               in.close();
>  
>                 } catch( SmbAuthException sae ) {
> //                       AUTHENTICATION FAILURE
>                         System.out.println("Authentication Failure.");
>                         sae.printStackTrace();
>                 } catch( SmbException se ) {
> //                       NETWORK PROBLEMS?
>                         System.out.println("Network problems."); 
>         } catch (IOException e) {
>             e.printStackTrace();
>                 } catch(Exception e) {
>                         e.printStackTrace();
>  
>                 }
> 
>         }
> 
> }
> 
> 
> 
> The content of this email, including any attachments, is a confidential
> communication between a GHD group company or a related entity (or the
> sender if this email is a private communication) and the intended
> addressee, and is for the sole use of that intended addressee. If you are
> not the intended addressee, any use, interference with, disclosure or
> copying of this material is unauthorised and prohibited. If you have
> received this email in error please contact the sender immediately and then
> delete the message and any attachment(s). There is no warranty that this
> email is error, virus or defect free. This email is also subject to
> copyright. No part of it should be reproduced, adapted or communicated
> without the written consent of the copyright owner. If this is a private
> communication, it does not represent the views of GHD or a related entity.
>  
> To  protect  GHD and staff, all email sent or received via GHD's systems is
> automatically  filtered and logged and may be examined at the discretion of
> management, without prior notification to the sender or recipient.
>  
> GHD  respects  your  privacy.  Our  privacy policy can be accessed from our
> website: www.ghd.com.au
> _____________________ 
> This e-mail has been scanned for viruses by MessageLabs.


-- 
Michael B Allen
PHP Active Directory SPNEGO SSO
http://www.ioplex.com/


More information about the jcifs mailing list