Example #1
0
        public override bool Interact(ref DirectoryInfo di, Command c)
        {
            var table = new ConsoleTable();
            foreach (var item in Directory.GetDirectories(di.FullName))
            {
                var d = new DirectoryInfo(item);

                table.PrintRow(d.Name, "<DIR>", d.CreationTime.ToShortDateString());
            }
            foreach (var item in Directory.GetFiles(di.FullName))
            {
                var d = new FileInfo(item);

                table.PrintRow(d.Name, "<FILE>", d.CreationTime.ToShortDateString());
            }
            return true;
        }
Example #2
0
        public override bool Interact(ref DirectoryInfo path, Command command)
        {
            switch (command.Arguments[0])
            {
                case "connect":
                    client.Host = command.Arguments[1];
                    Console.Write("Password: "******"disconnect":
                    client.Disconnect();

                    break;
                case "ls":
                    var ls = client.GetListing();
                    var t = new ConsoleTable();

                    t.PrintRow("Filename", "Size", "Type");
                    foreach (var li in ls)
                    {
                        if (li.Size == -1)
                        {
                            t.PrintRow(li.Name, "", "<Folder>");
                        }
                        else
                        {
                            t.PrintRow(li.Name, li.Size.ToString(), "<File>");
                        }
                    }
                    t.PrintLine();

                    break;
                case "exec":
                    client.Execute(command.Arguments[1]);
                    break;
                case "download":
                    MemoryStream s = null;
                    Stream ss = null;

                    try
                    {
                        ss = client.OpenRead(command.Arguments[1]);

                        // perform transfer
                    }
                    finally
                    {
                        if (s != null)
                        {
                            ss.CopyTo(s);
                            s.Close();
                        }
                    }

                    File.WriteAllBytes(command.Arguments[2], s.ToArray());

                    s.Close();

                    break;
            }

            return true;
        }