Beispiel #1
0
        private List <string> DownloadFromFtpSvr(System.Net.FtpClient.FtpClient ftpClient, string serverpath, string localDire)
        {
            var downloadFiles = new List <string>();

            foreach (var ftpItem in ftpClient.GetListing(serverpath, FtpListOption.Modify | FtpListOption.Size))
            {
                var descPath = $@"{localDire}\{ftpItem.Name}";
                if (File.Exists(descPath))
                {
                    File.Decrypt(descPath);
                }

                using (var ftpStream = ftpClient.OpenRead(ftpItem.FullName))
                {
                    using (var fileStream = File.Create(descPath, (int)ftpStream.Length))
                    {
                        var buffer = new byte[200 * 1024];
                        int count;

                        while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            fileStream.Write(buffer, 0, count);
                        }
                    }

                    downloadFiles.Add(ftpItem.Name);
                }
            }

            return(downloadFiles);
        }
Beispiel #2
0
        static Program()
        {
            Dictionary <string, Action> dictionary = new Dictionary <string, Action>();

            dictionary.Add("open", new Action(Program.Open));
            dictionary.Add("close", new Action(Program.Close));
            dictionary.Add("user", new Action(Program.User));
            dictionary.Add("use", new Action(Program.User));
            dictionary.Add("binary", new Action(Program.Binary));
            dictionary.Add("mkdir", () => Execute("MKD", true));
            dictionary.Add("rmdir", () => Execute("RMD", true));
            dictionary.Add("hash", delegate
            {
                hash = true;
                Console.WriteLine("hash opened.");
            });
            dictionary.Add("cd", () => Execute("CWD", true));
            dictionary.Add("lcd", new Action(Program.Lcd));
            dictionary.Add("clear", () => Console.Clear());
            dictionary.Add("mput", new Action(Program.Mput));
            dictionary.Add("rm", () => Execute("DELE", true));
            dictionary.Add("pwd", () => Execute("PWD", false));
            dictionary.Add("ls", delegate
            {
                if (CheckClient())
                {
                    foreach (FtpListItem item in client.GetListing())
                    {
                        Console.WriteLine(item.Name);
                    }
                }
            });
            Commands = dictionary;
        }