• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to change the permissions on a remote FTP Server ?  RSS feed

 
Srinivas S
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using org.apache.commons.net.ftp.* package for my FTP related activities in my code.

I want to store a file in the remote FTP server with write permission set to the file so that file can be overwritten by any one.

I am using storeFile(String rem,InputStream local) API to store the file in the remote server.But by default this API is storing the File on remote FTP server with "-rw-r--r--" permission .

Is there a way that I can change the permission bits for this file on the remote FTP server to make it writeable by anyone? If not can I set some properties before the call to storeFile() API so that the file is stored with required permissions set ?

Any help in this regard is highly Appreciated.

Thanks,
Srini


storeFile(String rem,InputStream local);
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The FTPFile class has hasPermission and setPermission methods. You can get an array of FTPFile through the listFiles method in FTPClient.
 
Srinivas S
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

Thanks for your reply, I tried to use these API's to set the file permission but not with much success.I am using the below code snapshot below to change the permission. I am able to set the permissions for the FTPFile objects in the FTPFile[] arrayList below.But this file permission change is not getting reflected to the file in the remote FTP server, Is there an API where I can store this FTPFile object with the modified file permission directly to the remote FTP server ?

FTPFile[] files=ftp.listFiles(ftpFileName);
for(int ii=0;ii<files.length;ii++){
for(int access=0;access<3;access++){
files[ii].setPermission(access,files[ii].READ_PERMISSION,true);
files[ii].setPermission(access,files[ii].WRITE_PERMISSION,true);
}
}


I have used storeFile(String remote, InputStream local) API to store a file remotely.But couldn't find any API's which can store the FTPFile object to the remote server.

Thanks,
Srini
 
Devashish Patyal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srinivas S wrote:Ulf,

Thanks for your reply, I tried to use these API's to set the file permission but not with much success.I am using the below code snapshot below to change the permission. I am able to set the permissions for the FTPFile objects in the FTPFile[] arrayList below.But this file permission change is not getting reflected to the file in the remote FTP server, Is there an API where I can store this FTPFile object with the modified file permission directly to the remote FTP server ?

FTPFile[] files=ftp.listFiles(ftpFileName);
for(int ii=0;ii<files.length;ii++){
for(int access=0;access<3;access++){
files[ii].setPermission(access,files[ii].READ_PERMISSION,true);
files[ii].setPermission(access,files[ii].WRITE_PERMISSION,true);
}
}


I have used storeFile(String remote, InputStream local) API to store a file remotely.But couldn't find any API's which can store the FTPFile object to the remote server.

Thanks,
Srini







any success on this.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!