[
https://issues.apache.org/jira/browse/SSHD-1130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17287587#comment-17287587
]
Lyor Goldstein commented on SSHD-1130:
--------------------------------------
I don't see how we can do that - we cannot tell that there aren't enough
permissions to list directory entries until we try to do it and get an
exception. Furthermore, please note that you are dealing with the +client+ side
so any "solution" we might provide depends heavily on the +server+ so it is out
of our hands...
> Sftp directory listing with permission denied error
> ---------------------------------------------------
>
> Key: SSHD-1130
> URL: https://issues.apache.org/jira/browse/SSHD-1130
> Project: MINA SSHD
> Issue Type: Improvement
> Affects Versions: 2.1.0, 2.6.0
> Reporter: Logan
> Priority: Major
>
> Iterating a directory with not enough permissions using DirectoryStream
> throws SftpException wrapped as RuntimeException on the iterator.next(),
> While this is perfectly valid with Iterator interface standard, to really
> determine if the issue is with permissions we have look at the cause of
> RuntimeException.
>
> {code:java}
> try (DirectoryStream<Path> ds = Files.newDirectoryStream(remoteDir)) {
> for (Path remoteFile : ds) { ..}
> } catch (RuntimeException ex) {
> Throwable cause = ex.getCause();
> if (cause != null && cause instanceof SftpException) {
> System.err.println("sftp error..probably permissions issue: " +
> ex.getMessage());
> } else {
> System.err.println("Unknown error: " + ex.getMessage());
> }
> }
> {code}
>
> On the flip side using SftpClient and SftpDirEntryIterator, an SftpException
> is throw in the constructor of SftpDirEntryIterator. This makes easy to
> determine that cause of the error for invalid permissions. So wondering if
> the implementation of SftpDirectoryStream can be improved throw SftpException
> in the constructor?
>
> {code:java}
> try (SftpDirEntryIterator pathIterator = new SftpDirEntryIterator(sftpClient,
> remotePath)) {
> while (pathIterator.hasNext()) {
> DirEntry dirEntry = pathIterator.next();
> ...
> }
> } catch (SftpException ex) {}
> {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]