Logan created SSHD-1130:
---------------------------
Summary: 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
Iterating a directory with no valid permission 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]