[
https://issues.apache.org/jira/browse/SSHD-1129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17287158#comment-17287158
]
Lyor Goldstein commented on SSHD-1129:
--------------------------------------
{quote}I believe JSch API was able to fetch user and group name along we other
details in some format ( I will try to get the code snippet soon)
{quote}
I would like to see that - provided they do it using +pure/standard SFTP+ and
not some undocumented extension or shell command. The API might also be
wrapping the integer UID/GID into some string thus giving the impression of a
user/group name (especially if it is ZERO=root) - but that does not mean they
provide the real value.
{quote}That said, if server is responding with UID/GUID what is the recommended
way of getting names?
{quote}
I doubt server is responding with UID/GUID names on SFTP v3. If it is SFTP v4
and above, then our code should be able to retrieve it provided it is being
sent via standard protocol. There may be a bug in our code, but in order to
verify we need to make sure that the server is sending the data correctly and
that we don't decode it somehow.
As far as other options - FYI, some SCP/SFTP clients use SSH +shell commands+
to provide extra data not incorporated in the SFTP protocol (e.g., WinSCP does
this in some cases). Therefore whatever API you are using may +seem+ to provide
the data you require but it does not do within the confines of the SFTP
protocol. This means that you can do the same - run some shell command on the
remote server and retrieve the user/group name - but beware since that is an
O/S specific command - which means you have to know what O/S is on the other
side and then tailor the command accordingly.
> 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]