Exemple #1
0
        internal static FtpFile Parse(string line)
        {
            var file = new FtpFile();

            if (string.IsNullOrEmpty(line))
            {
                return(file);
            }
            line = line.Trim();
            var      dateStart  = line.IndexOf(' ');
            var      dateString = line.Substring(dateStart + 1, 18);
            DateTime lastModified;

            if (DateTime.TryParse(dateString, out lastModified))
            {
                file.LastModified = lastModified;
            }
            int fileSize;

            if (int.TryParse(line.Substring(0, dateStart), out fileSize))
            {
                file.FileSize = fileSize;
            }
            file.FileName = line.Substring(dateStart + 20);
            return(file);
        }
        /// <summary>
        /// Lists the files in the directory.
        /// </summary>
        /// <param name="remoteDirectory">The remote directory.</param>
        /// <returns></returns>
        public virtual IEnumerable <FtpFile> ListDirectory(string remoteDirectory)
        {
            var request = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + RemoteHost + "/" + remoteDirectory));

            request.Method      = WebRequestMethods.Ftp.ListDirectory;
            request.Credentials = Credentials;
            request.UsePassive  = true;
            request.UseBinary   = true;
            request.KeepAlive   = false;
            using (Stream s = request.GetRequestStream())
                using (StreamReader sr = new StreamReader(s))
                    while (!sr.EndOfStream)
                    {
                        yield return(FtpFile.Parse(sr.ReadLine()));
                    }
        }
Exemple #3
0
 internal static FtpFile Parse(string line)
 {
     var file = new FtpFile();
     if (string.IsNullOrEmpty(line))
         return file;
     line = line.Trim();
     var dateStart = line.IndexOf(' ');
     var dateString = line.Substring(dateStart + 1, 18);
     DateTime lastModified;
     if (DateTime.TryParse(dateString, out lastModified))
         file.LastModified = lastModified;
     int fileSize;
     if (int.TryParse(line.Substring(0, dateStart), out fileSize))
         file.FileSize = fileSize;
     file.FileName = line.Substring(dateStart + 20);
     return file;
 }