• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Shajid Johnny
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/'.

 
Shajid Johnny
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic