This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Java file.mkdir() does not work even after chmod set to 777 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Java file.mkdir() does not work even after chmod set to 777" Watch "Java file.mkdir() does not work even after chmod set to 777" New topic
Author

Java file.mkdir() does not work even after chmod set to 777

Shajid Johnny
Ranch Hand

Joined: May 15, 2010
Posts: 34
Hello dear members,
I have no experience with Linux server. I am building a java application which will save files into server, uploaded by users. I have to deploy the application to a remote linux server. but the code of writing a file into that server seems not to be working. later i tried a simple jsp script to test if I can write any file to that server:



the directory var/www/vhosts/mysite.com/httpdocs are already existed in the server. I made all of their chmod = 777 through ftp.
but it does not create the folder and write the file.

I put the code into try catch and printed the exception- it shows:

Exception: java.io.FileNotFoundException: /var/www/vhosts/mysite.com/httpdocs/resources/write.txt (Permission denied)

can anyone please point me out my mistake if any? what could be the solution?

thanks in advance
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Well, the obvious thing to check is that the permissions on the "httpdocs" directory actually allow you to write to it. It's one thing to run a "chmod" command; it's another thing for that command to actually take effect.


[Jess in Action][AskingGoodQuestions]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Let's put some blanks in there, to allow for line breaks. (It doesn't work, until you fix your code too, because the rendering is oriented to the longest line on a page).
Shajid Johnny wrote:


In line 10, you declare 'file', but in line 5, you use it?

I don't guess it is the source of your problem, but the name of a folder/file is normally 'foo' and '/' is a separator. So '/a/b/c' is the whole pathname of folder c, not '/a/b/c/'.


http://home.arcor.de/hirnstrom/bewerbung
Shajid Johnny
Ranch Hand

Joined: May 15, 2010
Posts: 34
@Stefan Wagner

i am sorry, actually i had to edit the code snippet here, I missed that thing
my code did not have this error. it will be



I got your point. but the thing is- I tested this code in our local linux server and it worked fine!

I guess its a problem related to the permission level of that remote Linux server in which I am trying to deploy.

please be noted that- I set all the folders of the path to chmod=777. but I did not do that physically by logging in with putty or ssh. i did that using an FTP client.

should I try to test the mkdir command after physically logging in to that server by putty?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Can you please edit your initial post and insert some blanks, to allow the layout to break your very long line, please?

Did you, as EFH suggested, check, whether chmod had the desired effect?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15961
    
  19

It's very likely that selinux is forbidding the operation. On Red Hat-style distros, the message would appear in the /var/log/audit file. You can use the "Z" option of the ls command to see selinux attributes ("ls -lZ /var/www")

Regardless, I don't recommend writing to the /var/www directory or its children. That's opening up your webapps for exploits. The preferable place for writable webapp-related files is generally something like /var/lib/myappname. And, of course, absolutely positively never write files to locations inside of your deployed WAR!


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java file.mkdir() does not work even after chmod set to 777
 
Similar Threads
mod_jk tries to map every request from apache
Creating file in the web server
java.io.FileNotFoundException
Creating file in the web server
Setting path dynamically in oreilly API