Added SftpCommandMain 'lls' (local-LS) command support
@@ -117,6 +117,7 @@ public class SftpCommandMain extends SshClientCliSupport implements Channel {
new LcdCommandExecutor(),
new MkdirCommandExecutor(),
new LsCommandExecutor(),
+ new LlsCommandExecutor(),
new LStatCommandExecutor(),
new ReadLinkCommandExecutor(),
new RmCommandExecutor(),
@@ -709,6 +710,61 @@ public class SftpCommandMain extends SshClientCliSupport implements Channel {
/* -------------------------------------------------------------------- */
+ private class LlsCommandExecutor implements SftpCommandExecutor {
+ LlsCommandExecutor() {
+ super();
+ }
+
+ @Override
+ public String getName() {
+ return "lls";
+ }
+
+ @Override
+ public boolean executeCommand(
+ String args, BufferedReader stdin, PrintStream stdout, PrintStream stderr)
+ throws Exception {
+ String[] comps = GenericUtils.split(args, ' ');
+ int numComps = GenericUtils.length(comps);
+ String pathArg = (numComps <= 0) ? null : GenericUtils.trimToEmpty(comps[numComps - 1]);
+ String flags = (numComps >= 2) ? GenericUtils.trimToEmpty(comps[0]) : null;
+ // ignore all flags
+ if ((GenericUtils.length(pathArg) > 0) && (pathArg.charAt(0) == '-')) {
+ flags = pathArg;
+ pathArg = null;
+ }
+
+ Path local = Paths.get(resolveLocalPath(pathArg)).normalize().toAbsolutePath();
+ if (Files.notExists(local)) {
+ stderr.println("File/Folder not found");
+ } else if (Files.isDirectory(local)) {
+ try (DirectoryStream<Path> ds = Files.newDirectoryStream(local)) {
+ for (Path path : ds) {
+ displayLocalPathInfo(path, stdout);
+ }
+ }
+ } else if (Files.isRegularFile(local)) {
+ displayLocalPathInfo(local, stdout);
+ } else {
+ stderr.println("Unsupported special file");
+ }
+
+ return false;
+ }
+
+ protected void displayLocalPathInfo(Path path, PrintStream stdout) throws IOException {
+ stdout.append('\t').append(Objects.toString(path.getFileName()));
+ if (Files.isRegularFile(path)) {
+ stdout.append(' ').append(Long.toString(Files.size(path)));
+ } else {
+ stdout.append('/');
+ }
+ stdout.println();
+ }
+ }
+
+ /* -------------------------------------------------------------------- */
+
private class RmCommandExecutor implements SftpCommandExecutor {
RmCommandExecutor() {
super();
