Example #1
0
        public EntryInfoBase[] ListRepositories(string path)
        {
            List <EntryInfoBase> entries = new List <EntryInfoBase>();

            //create ftp web request
            FtpWebRequest request = this.CreateWebRequest(WebRequestMethods.Ftp.ListDirectoryDetails, this.GetValidPath(this._host, path));

            //get ftp response
            FtpWebResponse response = this.GetResponse(request);

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                //add all file path
                while (!reader.EndOfStream)
                {
                    EntryInfoBase entry = EntryInfoBase.Parse(reader.ReadLine(), path);
                    entries.Add(entry);
                }
            }

            //Close connection
            response.Close();
            request.Abort();

            return(entries.ToArray());
        }
Example #2
0
            internal static EntryInfoBase Parse(string info, string parentPath)
            {
                EntryInfoBase entry = null;

                //parse line
                Match match = EntryInfoBase.GetMatch(info);

                if (match == null)//failed
                {
                    throw new ArgumentException(string.Format("Parsing error:{0}", info));
                }
                else
                {
                    //Parsing attribute
                    string name       = match.Groups["name"].Value;
                    string permission = match.Groups["permission"].Value;

                    //Parsing time
                    DateTime time;
                    try
                    {
                        time = DateTime.Parse(match.Groups["timestamp"].Value);
                    }
                    catch (Exception)
                    {
                        time = new DateTime();
                    }

                    //Check is file or directory
                    string dir = match.Groups["dir"].Value;
                    if (!string.IsNullOrEmpty(dir) && dir != "-")
                    {
                        entry = new DirectoryEntryInfo(name, time, permission, parentPath);
                    }
                    else
                    {
                        long size = 0;
                        try
                        {
                            size = Convert.ToInt64(match.Groups["size"].Value);
                        }
                        catch (Exception)
                        {
                        }

                        //Parsing extension
                        string extension = null;
                        int    i         = name.LastIndexOf(".");
                        if (i >= 0 && i < name.Length - 1)
                        {
                            extension = name.Substring(i + 1);
                        }

                        entry = new FileEntryInfo(name, time, size, extension, permission, parentPath);
                    }
                }

                return(entry);
            }