• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Saloon Keeper
Posts: 28584
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
reply
    Bookmark Topic Watch Topic
  • New Topic