Giving permission to a ftp FILE java

点点圈 提交于 2019-12-25 05:46:09

问题


i have a class in android that connect with the ftp, and store an image, that works perfect the problem is when i am trying to move the image to another directory( i use a php page to moderate that image) it doesnt have permission to handle it, i want to put the permission to 0777 but only the "java code" can do it but i dont know how,

I am using FTPClient library

this is my code

 File imageFile = new File(url[0]); 



         FTPClient ftpClient = new FTPClient();   ftpClient.connect(InetAddress.getByName("myserver"));
         ftpClient.login("login", "pass");

         ftpClient.changeWorkingDirectory("directory");
         ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
         BufferedInputStream buffIn=null;
         buffIn=new BufferedInputStream(new FileInputStream(imageFile));
         ftpClient.enterLocalPassiveMode();
         ftpClient.storeFile(url[1]+".jpg", buffIn);
         buffIn.close();
         ftpClient.logout();
         ftpClient.disconnect();

回答1:


See the FTPClient and FTPFile API You can do something like that :

...
ftpClient.storeFile(url[1]+".jpg", buffIn);
FTPFile file = ftpClient.mlistFile(url[1]+".jpg");
file.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION, true);
file.setPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION, true);
...



回答2:


I made it by command

 ftpClient.storeFile(url[1]+".jpg", buffIn);
         boolean a = ftpClient.sendSiteCommand("chmod " + "777 " + "/absolutepath/"+url[1]+".jpg");


来源:https://stackoverflow.com/questions/17040563/giving-permission-to-a-ftp-file-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!