예제 #1
0
        static void Main(string[] args)
        {
            var server   = args[0];
            var path     = args[1];
            var username = args[2];
            var password = args[3];

            var ftpService = new FtpService(server, path, username, password);

            ftpService.FtpLogin();

            ftpService.Rename("MainForm.cs", "test.poi", true);

            ftpService.CloseConnection();
        }
예제 #2
0
        private static void Main(string[] args)
        {
            while (true)
            {
                Console.Write("KT-ftp> ");

                var cmd = Console.ReadLine();
                if (cmd != null)
                {
                    switch (cmd.Split(" ")[0])
                    {
                    case "open":
                        if (ftp != null)
                        {
                            break;
                        }
                        ftp = new FtpService(cmd.Split(" ")[1], 21);
                        Console.Write("User: "******"Password: "******"";

                        while (true)
                        {
                            var key = Console.ReadKey(true);
                            if (key.Key == ConsoleKey.Enter)
                            {
                                break;
                            }

                            pass += key.KeyChar;
                        }
                        Console.WriteLine();

                        if (ftp.Login(user, pass))
                        {
                            Console.WriteLine($"Connected to {cmd.Split(" ")[1]}");
                        }
                        else
                        {
                            ftp = null;
                            Console.WriteLine("Connection failed!");
                        }

                        break;

                    case "ls":
                        if (ftp != null)
                        {
                            if (cmd.Split(" ").Length > 1)
                            {
                                ftp.ReceiveData("LIST " + cmd.Split(" ")[1]).Print();
                            }

                            ftp.ReceiveData("LIST").Print();
                        }
                        break;

                    case "cd":
                        if (ftp != null)
                        {
                            ftp.ExecuteCommand($"CWD {cmd.Split(" ")[1]}").Print();
                        }
                        break;

                    case "cdup":
                        if (ftp != null)
                        {
                            ftp.ExecuteCommand($"CDUP").Print();
                        }
                        break;

                    case "delete":
                        if (ftp != null)
                        {
                            ftp.ExecuteCommand($"DELE {cmd.Split(" ")[1]}").Print();
                        }
                        break;

                    case "mdelete":
                        for (int i = 1; i < cmd.Split(" ").Length; i++)
                        {
                            string path = cmd.Split(" ")[i];
                            ftp.ExecuteCommand($"DELE {cmd.Split(" ")[i]}").Print();
                        }
                        break;

                    case "get":
                        if (ftp != null)
                        {
                            byte[] data = ftp.ReceiveFile(cmd.Split(" ")[1]);
                            File.WriteAllBytes(cmd.Split(" ")[2], data);
                        }
                        break;

                    case "send":
                        if (ftp != null)
                        {
                            ftp.Upload(cmd.Split(" ")[1], cmd.Split(" ")[2]);
                        }
                        break;

                    case "mget":
                        Console.Write("Directory: ");
                        var directoryPath = Console.ReadLine();

                        if (directoryPath.Last() != '/' || directoryPath.Last() != '\\')
                        {
                            directoryPath += '/';
                        }

                        for (int i = 1; i < cmd.Split(" ").Length; i++)
                        {
                            string fromPath = cmd.Split(" ")[i];
                            string toPath   = directoryPath + fromPath;

                            byte[] data = ftp.ReceiveFile(fromPath);
                            File.WriteAllBytes(toPath, data);
                        }
                        break;

                    case "msend":
                        for (int i = 1; i < cmd.Split(" ").Length; i++)
                        {
                            string fromPath = cmd.Split(" ")[i];
                            string toPath   = fromPath.Split("/").Last();

                            ftp.Upload(fromPath, toPath);
                        }
                        break;

                    case "mkdir":
                        ftp.ExecuteCommand("MKD " + cmd.Split(" ")[1]).Print();
                        break;

                    case "rmdir":
                        ftp.ExecuteCommand("RMD " + cmd.Split(" ")[1]).Print();
                        break;

                    case "rrmdir":
                        DeleteFolderRecursively(cmd.Split(" ")[1]);
                        break;

                    case "zip":
                        ConstructZipFile(cmd.Split(" ")[1], cmd.Split(" ")[2]);
                        break;

                    case "binary":
                        if (ftp != null)
                        {
                            ftp.ExecuteCommand("TYPE I").Print();
                        }
                        break;

                    case "ascii":
                        if (ftp != null)
                        {
                            ftp.ExecuteCommand("TYPE A").Print();
                        }
                        break;

                    case "bye":
                        Console.WriteLine("Bye!");
                        ftp.ExecuteCommand("QUIT").Print();
                        Environment.Exit(0);
                        break;

                    default:
                        System.Console.WriteLine("Command not found!");
                        break;
                    }
                }
            }
        }