コード例 #1
0
        //- Download Files and Folders to Client
        public void DownloadToClient(string client_directory)
        {
            List <FTP.Data> every_data = GetData(ServerIP);

            List <FTP.Data> real = new List <FTP.Data>();

            SetRealList(real, every_data);

            foreach (FTP.Data data in real)
            {
                if (data is FTP.Directory)
                {
                    FTP.Directory local          = (FTP.Directory)data;
                    string        full_real_path = local.FullPath;
                    full_real_path = full_real_path.Substring(ServerIP.Length, full_real_path.Length - ServerIP.Length);
                    if (!Directory.Exists(client_directory + @"\" + full_real_path))
                    {
                        Directory.CreateDirectory(client_directory + @"\" + full_real_path);
                    }
                }
                if (data is FTP.File)
                {
                    FTP.File local          = (FTP.File)data;
                    string   full_real_path = local.FullPath;
                    full_real_path = full_real_path.Substring(ServerIP.Length, full_real_path.Length - ServerIP.Length);
                    if (!File.Exists(client_directory + @"\" + full_real_path))
                    {
                        CreateClientFile(client_directory + @"\" + full_real_path, local.Content);
                    }
                }
            }
        }
コード例 #2
0
        //- Downloads data information from server
        private List <FTP.Data> GetData(string full_path)
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(full_path);

            request.Method      = WebRequestMethods.Ftp.ListDirectoryDetails;
            request.Credentials = new NetworkCredential(Username, Password);

            string[] files_or_folders = null;
            using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    files_or_folders = reader.ReadToEnd().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                }
            }

            List <FTP.Data> DataList = new List <FTP.Data>();

            foreach (string txt in files_or_folders)
            {
                string original  = txt;
                string data_name = txt.Substring(49, txt.Length - 49);

                string file_check = original.Substring(0, 1);
                if (file_check == "d")
                {
                    //- Directory
                    FTP.Directory dir = new FTP.Directory();
                    dir.UriCode  = original;
                    dir.Name     = data_name;
                    dir.FullPath = full_path + "/" + dir.Name;
                    dir.Children = new List <FTP.Data>();
                    DataList.Add(dir);
                    foreach (FTP.Data directory in GetData(dir.FullPath))
                    {
                        dir.Children.Add(directory);
                    }
                }
                else
                {
                    //- File
                    FTP.File file = new FTP.File();
                    file.UriCode  = original;
                    file.Name     = data_name;
                    file.FullPath = full_path + "/" + file.Name;
                    string[] splitted = data_name.Split('.');
                    file.Extension = "";
                    file.Content   = Download(file.FullPath);
                    if (splitted.Length == 2)
                    {
                        file.Extension = splitted[1];
                    }
                    DataList.Add(file);
                }
            }

            return(DataList);
        }