Move File from /tmp to hosting account folder

1.4k Views Asked by At

I have write access to /tmp folder of my shared hosting account at godaddy. I want to move uploaded pictures from /tmp folder to my hosting account folder /home/content/x/y/z/xyz/html/pic/ I am trying to move file through jsp with no success. Folder permissions are set to (read write execute 0777). Godaddy support insists that transfer of file is possible. I am totally stuck and need help in this regard.

When I use linux command(mv/cp) I get below exception:

Process p = Runtime.getRuntime().exec("mv /tmp/"+fileName+"  /home/content/x/y/z/xyz/html/pic/ "+fileName);

Error: java.security.AccessControlException: access denied (java.io.FilePermission <> execute)

When I write it through stream I get below exception:

OutputStream bos = new FileOutputStream( "/home/content/x/y/z/xyz/html/pic/"+filename);
bos.write(buffer, 0, bytesRead);

ERROR: java.security.AccessControlException: access denied(java.io.FilePermission/home/content/x/y/z/xyz/html/pic/DSC00061.JPG write

1

There are 1 best solutions below

2
BalusC On

The first error tells that you're not allowed to execute commandline commands, which is very reasonable. The second error is however not very positive. You could at least try File#renameTo().

File source = new File("/tmp", fileName);
File destination = new File("/home/content/x/y/z/xyz/html/pic", fileName);
source.renameTo(destination);