Beispiel #1
0
        //---------------------------------------------------------------------
        public override void List(Commands.ListEntriesCommand Command)
        {
            if (this._ShellAdapter.Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("List", "FileSystem root is undefined");
            }
            string syspath = this.MakeSystemPathname(this._ShellAdapter.Root, Command.in_Pathname);

            // Get file listing.
            string ShellCommand = "";

            if (this._ShellAdapter.ProtocolName.Equals("ssh", StringComparison.InvariantCultureIgnoreCase))
            {
                ShellCommand = "ls -l " + syspath + "/";
            }
            else if (this._ShellAdapter.ProtocolName.Equals("scp", StringComparison.InvariantCultureIgnoreCase))
            {
                ShellCommand = "ls " + syspath + "/";
            }
            string output = this._ShellAdapter.ExecuteCommand(ShellCommand);

            string[] lines = output.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);

            // Parse listing output.
            FileSystemItemList items = new FileSystemItemList();

            foreach (string line in lines)
            {
                FileSystemItem item = UnixShell.ParseLsOutput(Command.in_Pathname, line);
                if (item != null)
                {
                    if (item.IsLink)
                    {
                        if (Command.in_IncludeLinks)
                        {
                            items.AddSorted(item);
                        }
                    }
                    else if (item.IsFolder)
                    {
                        if (Command.in_IncludeFolders)
                        {
                            items.AddSorted(item);
                        }
                    }
                    else
                    {
                        if (Command.in_IncludeFiles)
                        {
                            items.AddSorted(item);
                        }
                    }
                }
            }

            // Return, OK.
            Command.out_ItemList = items;
            return;
        }
Beispiel #2
0
        //---------------------------------------------------------------------
        public override void Read(Commands.ReadItemCommand Command)
        {
            if (this._ShellAdapter.Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("Read", "FileSystem root is undefined");
            }
            string syspath = this.MakeSystemPathname(this._ShellAdapter.Root, Command.in_Pathname);

            // Get file listing.
            string ShellCommand = "";

            if (this._ShellAdapter.ProtocolName.Equals("ssh", StringComparison.InvariantCultureIgnoreCase))
            {
                ShellCommand = "ls -l " + syspath;
            }
            else if (this._ShellAdapter.ProtocolName.Equals("scp", StringComparison.InvariantCultureIgnoreCase))
            {
                ShellCommand = "ls " + syspath;
            }
            string output = this._ShellAdapter.ExecuteCommand(ShellCommand);

            string[] lines = output.Split(new string[] { "\n" }, StringSplitOptions.None);

            // Parse listing output.
            FileSystemItemList items = new FileSystemItemList();

            foreach (string line in lines)
            {
                FileSystemItem item = UnixShell.ParseLsOutput(Command.in_Pathname, line);
                if (item != null)
                {
                    if (string.Equals(item.Pathname, syspath, StringComparison.InvariantCultureIgnoreCase) == true)
                    {
                        item.Pathname = Command.in_Pathname;
                        items.AddSorted(item);
                    }
                }
            }
            if (items.Count == 1)
            {
                Command.out_Item = items[0];
            }
            else
            {
                Command.out_Item          = new FileSystemItem();
                Command.out_Item.Pathname = Command.in_Pathname;
                Command.out_Item.IsFolder = true;
                Command.out_Item.Exists   = true;
            }

            // Return, OK.
            return;
        }