示例#1
0
        /// <summary>
        /// Returns a collection of entries that represent directories and files
        /// in the current specified directory on the server.
        /// </summary>
        /// <param name="directory">The directory to list contents of.</param>
        public FtpListingDetail[] ListDirectoryDetails(string directory)
        {
            try
            {
                List<FtpListingDetail> lst = new List<FtpListingDetail>();

                FtpWebRequest request = CreateRequest(directory);
                request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                request.UseBinary = false;

                FtpWebResponse response = request.GetResponse() as FtpWebResponse;
                Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(response.StatusDescription); Console.ResetColor();
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    string line = sr.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        FtpListingDetail detail = new FtpListingDetail(line);
                        lst.Add(detail);
                        line = sr.ReadLine();
                    }
                }
                response.Close();

                return lst.ToArray();
            }
            catch (Exception ex) { HandleException(ex); }

            return null;
        }
示例#2
0
        /// <summary>
        /// Returns a collection of entries that represent directories and files
        /// in the current specified directory on the server.
        /// </summary>
        /// <param name="directory">The directory to list contents of.</param>
        public FtpListingDetail[] ListDirectoryDetails(string directory)
        {
            try
            {
                List<FtpListingDetail> lst = new List<FtpListingDetail>();

                FtpWebRequest request = CreateRequest(directory);
                request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                request.UseBinary = false;

                FtpWebResponse response = request.GetResponse() as FtpWebResponse;
                Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(response.StatusDescription); Console.ResetColor();
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    string line = sr.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        FtpListingDetail detail = new FtpListingDetail(line);
                        lst.Add(detail);
                        line = sr.ReadLine();
                    }
                }
                response.Close();

                return lst.ToArray();
            }
            catch (Exception ex) { HandleException(ex); }

            return null;
        }