[ 
https://issues.apache.org/jira/browse/SSHD-1129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17287282#comment-17287282
 ] 

Logan commented on SSHD-1129:
-----------------------------

I stand corrected with Jsch API support for owner and group details. Currently 
Jsch API return 0 for UID/GID in line with their [documentation 
|https://epaul.github.io/jsch-documentation/javadoc/com/jcraft/jsch/SftpATTRS.html]
 Here is the code snippet just in case.

Is there a way to know server O/S ?

 
{code:java}
public void testWithJsch()
 throws IOException, JSchException, com.jcraft.jsch.SftpException {
  final JSch jsch = new JSch();
  Session session = null;
  try {
    session = jsch.getSession(user, hostname, port);
    Properties sessionProps = new Properties();
    sessionProps.put("StrictHostKeyChecking", "no");
    session.setPassword(password);
    session.setConfig(sessionProps);
    session.setServerAliveInterval(300000);
    session.connect(60000);
    ChannelSftp channelSftp = null;
    try {
      channelSftp = (ChannelSftp) session.openChannel("sftp");
      channelSftp.connect(60000);
      Vector<ChannelSftp.LsEntry> entries = channelSftp.ls("/tmp");
      for (LsEntry entry : entries) {
        SftpATTRS attrs = entry.getAttrs();
        System.out.println("owner id: " + attrs.getUId() + " group id: " + 
attrs.getGId() + " extended: " + toString(attrs.getExtended()));
      }
    } finally {
      if (channelSftp != null) {
        channelSftp.disconnect();
      }
  }
  } finally {
     if (session != null) {
     session.disconnect();
  }
}
}
{code}
 

> Posix file owner and group always null
> --------------------------------------
>
>                 Key: SSHD-1129
>                 URL: https://issues.apache.org/jira/browse/SSHD-1129
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 2.1.0, 2.6.0
>            Reporter: Logan
>            Priority: Major
>
> Unable to read remote path owner and group details when connected through 
> sftp. Below is code snippet.
>  
> {code:java}
> public void singlePath() throws IOException {
>   try (SshClient client = SshClient.setUpDefaultClient()) {
>     client.start();
>       try (ClientSession session = client.connect("user", "host", 
> 22).verify(SFTP_SESSION_TIME_OUT_MILLIS).getSession()) {
>         session.addPasswordIdentity("xxxx");
>         session.auth().verify(SFTP_SESSION_TIME_OUT_MILLIS);
>        SftpFileSystemProvider provider = new SftpFileSystemProvider(client);
>        String[] paths = new String[] { "/tmp" };
>        try (FileSystem fs = provider.newFileSystem(session)) {
>           boolean posix = fs.supportedFileAttributeViews().contains("posix");
>          for (String path : paths) {
>             System.out.println(path + ":");
>             Path remotePath = fs.getPath(path);
>             if (posix) {
>                 PosixFileAttributes posixAttrs = Files
>  .getFileAttributeView(remotePath, PosixFileAttributeView.class)
>  .readAttributes();
>                 Set<PosixFilePermission> perms = posixAttrs.permissions();
>                 System.out.println(PosixFilePermissions.toString(perms));
>                 UserPrincipal user = posixAttrs.owner();
>                 System.out.println(user == null ? "NULL" : user.getName());
>                 GroupPrincipal group = posixAttrs.group();
>                 System.out.println(group == null ? "NULL" : group.getName());
>              }
>           }
>        }
>      }
>   }
>  }
> {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to