• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"Access is denied" when trying to read a file on remote windows box from a servlet

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to figure out how to view a "shared" remote file via my serlvet.

I was able to log on to the box manually and open the log file by giving username and password.
But how do I provide username and password from my servlet when opening the remote file:
\\aRemoteWindowsBox\d$\aDir\aFile

.........
FileReader inputFileReader = new FileReader("\\aRemoteWindowsBox\d$\aDir\aFile");
BufferedReader inputStream = new BufferedReader(inputFileReader);

while (( aLine = inputStream.readLine()) != null)
{ process each line
}
inputStream.close();
..........


This code gives me the following error when accessing a shared file on a remote box:

"Java.io.FileNotFoundException: //aRemoteBox/d$/aDir/aFile (Access is denied.)"

Thank you for any help!!
--Renee
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use jCIFS to access remote servers over a Windows network from Java.

http://jcifs.samba.org/
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the servlet/web server run under the same account you use to access the file directly? Does it run with a security manager?
 
Renee Lee
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul and Ulf for your replies!

Paul -- JCIFS seems a very nice tool! Thanks for the link! Since the servlet is accessing files on production boxes. I'm trying to avoid put any extra stuff on production boxes though.

Ulf -- my servlet is running on weblogic server (8.1sp5) on windows. I don't think it runs with a security manager (by default, I believe it's disabled with weblogic). No policy file is used either.

I still haven't figured it out yet Any suggestion are greatly appreciated!
Thank you for help and have a nice weekend!
--Renee
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Renee Lee:
Paul -- JCIFS seems a very nice tool! Thanks for the link! Since the servlet is accessing files on production boxes. I'm trying to avoid put any extra stuff on production boxes though.

I know what you mean -- we recently had to add a job that accessed one of our business partners via a web services, and now we have 46 jar files in our classpath. I'm not kidding about that, we really have 46 jar files.

But just to be clear, if you want to use JCIFS, you only need to put it on the machine where your servlet is running (just drop it in your application's WEB-INF/lib directory). You don't have to put it on the machine you want to grab files from; all you need is a user ID and password for that machine, and you already have that.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

my servlet is running on weblogic server (8.1sp5) on windows.


Yes, but what account does that run under? The account needs to have access rights, and server accounts usually have fewer rights than intercative user accounts (like, e.g., accessing remote machines).

jCIFS is cool, though. And since it mimics the java.io.File API, very easy to use.
 
Renee Lee
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Paul and Ulf for your replies!!

JCIFS seems the right diretion for me.
But I'm getting this error:
"jcifs.smb.SmbException: The network name cannot be found.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:510)
at jcifs.smb.SmbTransport.send(SmbTransport.java:610)
at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:269)
at jcifs.smb.SmbSession.send(SmbSession.java:225)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:147)
at jcifs.smb.SmbFile.connect(SmbFile.java:791)
at jcifs.smb.SmbFile.connect0(SmbFile.java:761)
at jcifs.smb.SmbFile.open0(SmbFile.java:816)
at jcifs.smb.SmbFile.open(SmbFile.java:845)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:69)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:62)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:49)
at viewfiles_servlet.view_server_log(viewfiles_servlet.java:107)
at viewfiles_servlet.doPost(viewfiles_servlet.java:78)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1072)
..........."

I'm trying some baby steps. here is my code:
" jcifs.Config.setProperty( "jcifs.netbios.wins", "10.xx.aa.bbb" );

SmbFileInputStream in = new SmbFileInputStream(
"smb://ameriquest.net;Myusername:Mypassword@10.xx.aa.bbb/d/bea_projects/domains/tracs_domain/logs/tracks.log" );

byte[] b = new byte[8192];
int n;
while(( n = in.read(b)) > 0 )
{
System.out.write(b,0, n);
}"

questions:
1. I'm searching on google... didn't get much clue (

2. I'm having 3 internal domains and each has 40 windows boxes and some linux boxes
How do I specify all these variables in web.xml?

3. for
jcifs.smb.client.domain
jcifs.smb.client.username
jcifs.smb.client.password
I've specified the above 3 things in the code so there's no need to put them in web.xml file, right?

4. I don't see "readline()" available in JCIFS. Is there another way to do similar thing as readline() in BufferedReader?

any help will be greatly appreciated )
Thank you!!
--Renee
 
Renee Lee
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried with the following code:

"import jcifs.Config;
import jcifs.smb.SmbFile;

public class ListShares {
public static void main(String[] args) throws Exception {
Config.setProperty("jcifs.smb.client.username", args[0]);
Config.setProperty("jcifs.smb.client.password", args[1]);
SmbFile[] shares = new SmbFile(args[2]).listFiles();
for (int i = 0; i < shares.length; i++) {
System.out.println(shares[i]);
}
}
}"

And I did see "smb://xx.yy.zz.aaa/IPC$/" in the output list.

What on earth is cause the following error:
"jcifs.smb.SmbException: The network name cannot be found.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:510)
at jcifs.smb.SmbTransport.send(SmbTransport.java:610)...."??

Thanks for any pointers!!!
--Renee
 
Renee Lee
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
smb url syntax:

If I could view the file on the remote windows box as:
"\\cscw-wlipro01\d$\bea_projects\domains\tracs_domain\logs\tracks.log"

Then, is this right with smb?
"smb://ameriquest.net;myusername:mypassword@cscw-wlipro01/d$/bea_projects/domains/tracs_domain/logs/tracks.log"

Thanks in advance for any help!!
--Renee
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
I know what you mean -- we recently had to add a job that accessed one of our business partners via a web services, and now we have 46 jar files in our classpath. I'm not kidding about that, we really have 46 jar files.



Paul, I can imagine it's not fun to have 46 JARs in your classpath, but there are ways to make it more manageable. Have a look at http://one-jar.sourceforge.net/ for example.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

smb://ameriquest.net;myusername:mypassword@cscw-wlipro01/d$/bea_projects/domains/tracs_domain/logs/tracks.log"



I struggled with the right syntax until I finally gave up and used the IP address, in which case the URL looks like:

smb://username:password@www.xxx.yyy.zzz/share_name/file.name
[ May 24, 2006: Message edited by: Ulf Dittmer ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic