Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access network path from within servlet

Status
Not open for further replies.

UltraSmooth

Programmer
Oct 28, 2002
97
CA
I'm trying to copy some files from a network path from within a servlet. I realize that I cannot use drive letter mappings as they are profile specific. Instead I'm trying to use the unc path. I'm getting the following error when I read the error inputstream from the process:

Command: xcopy \\COMPUTER\FOLDER\File.dat C:\FOLDER\ /Y

0 File(s) copied
Invalid drive specification
Exit code: 4

What permissions should I put on the shared folder to allow this, or is it a path problem?

Any help would be appreciated.
 
Works for me in command line if the folder is a shared resource name but ... how are you executing that from the servlet?

Cheers,
Dian
 
It works from the command line for me as well, the problem I'm guessing is that Tomcat runs at as service under the SYSTEM account. When I'm logged in and running it from the command line or from the IDE it works fine but when run in the tomcat/webapp environment it fails. Here's how I'm running it:

String cmd = "XCOPY \\SERVER\SHARE\File.DAT C:\FOLDER /Y"
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(cmd);
p.waitFor(); //execute process and wait for it to finish
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream());

....

Any ideas?
 
The System account may not have access to the UNC drives.
In the Services tab for Tomcat, have the service start as a user who can.

BTW, why on earth are you using an OS xcopy routine to copy a file ??? Just do it in Java !

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Well in done java the same problem occurs:

java.io.FileNotFoundException: \\SERVER\SHARE\File.DAT (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at ....

Error: \\SERVER\SHARE\File.DAT (Access is denied)
 
Starting the Tomcat service under the Administrator account fixes the problem, is there any reason I shouldn't use the Administrator account for this?
 
I know that Java will have the same problem - thats not my point. My point is that its daft not doing it in Java.

The fundamental error is that you need to set the user that Tomcat is running as to have permissions to write/read that directory - which is an OS question - not a Java or Tomcat question.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top