Hi,

the method described by Andre is right for the user-permissions.

To be correct, you also need to check whether the owner of the
file is your current user. Unfortunately, Sftp only gives you
the numerical user ID on the remore system, so that check is
not trivial (though you can create a test file in the home
directory and then read the UID of the file you created) :

   SftpATTRS.getUId()  // user ID
   SftpATTRS.getGId()  // group ID

For the "group" permissions, I'm not aware of any possibility
to reliably check whether your user could write a file or not,
because I don't know how you could check whether your user is
a member of any given group with ID x or not.

What I ended up doing in our application is a mark a file as
read-only if and only if the the write permission is turned
of for *all* user,group,others. As soon as *any one* of them
is writeable, I'd mark  the file writable. 

But be prepared for an exception because trying to write a
file that's writable for a user, but belongs to a different
user, would still not be possible.

Cheers,
--
Martin Oberhuber, Senior Member of Technical Staff, Wind River
Target Management Project Lead, DSDP PMC Member
http://www.eclipse.org/dsdp/tm
 
 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Andre Charbonneau
> Sent: Monday, September 15, 2008 3:57 PM
> To: sai kiran
> Cc: [email protected]
> Subject: Re: [JSch-users] Need help
> 
> Hi,
> The way I do it in my application is that I use the ChannelSftp.stat()
> method to fetch the statistics about a file.  For example:
> 
> ChannelSftp sftp = ...
> 
> SftpATTRS attributes = sftp.stat("/path/to/remote/file");
> 
> boolean canRead = (attributes.getPermissions() & 00400) != 0;
> boolean canWrite = (attributes.getPermissions() & 00400) != 0;
> ...
> 
> Or there is another method named 
> attributes.getPermissionsString() that
> you can use to fetch permission for this file.
> 
> 
> Hope this helps...
> 
>       Andre
> 
> sai kiran wrote:
> > Hi All
> >  
> > I am using the JSCH 0.1.37 version. I am usig SFTP Chanel for doing
> > several activites like storing a file/Appending to a file contents.
> >  
> > I want to find the write permissions for the current logged 
> in users on
> > a file.
> >  
> > Is this possible? Please let me know the best mechnisam to find this
> >  
> > thanks a lot
> > sai
> > 
> > 
> > 
> --------------------------------------------------------------
> ----------
> > 
> > 
> --------------------------------------------------------------
> -----------
> > This SF.Net email is sponsored by the Moblin Your Move 
> Developer's challenge
> > Build the coolest Linux based applications with Moblin SDK 
> & win great prizes
> > Grand prize is a trip for two to an Open Source event 
> anywhere in the world
> > http://moblin-contest.org/redirect.php?banner_id=100&url=/
> > 
> > 
> > 
> --------------------------------------------------------------
> ----------
> > 
> > _______________________________________________
> > JSch-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/jsch-users
> 
> 
> -- 
> Andre Charbonneau
> Research Computing Support, IMSB
> National Research Council Canada
> 100 Sussex Drive, Rm 2025
> Ottawa, ON, Canada K1A 0R6
> 613 993-3129
> 
> --------------------------------------------------------------
> -----------
> This SF.Net email is sponsored by the Moblin Your Move 
> Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & 
> win great prizes
> Grand prize is a trip for two to an Open Source event 
> anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> JSch-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jsch-users
> 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to