本文介绍了如何使用C#.net获取FTP或目录中的最新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人

我有一个要求,就是我必须从FTP中存在的目录中下载最新文件.
是否可以从列表中仅获取最新文件?

等待回复,


问候
Ramesh

Dear All

I have a requirement that is i have to download the latest files from the directory which is present in FTP.
Is it possible to get only the latest file from the list?

waiting for reply,


Regards
Ramesh

推荐答案

// Your FTP site
string ftpPath = "ftp://some/localtion/to/ftp/directory/";

// Some expression to match against the files...do they have a consistent name? This example would find XML files that had 'some_string' in the file name
Regex matchExpression = new Regex("^some_string.+\.xml




源代码



Source Code

namespace FTP.Utilities
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.IO;
    using System.Text.RegularExpressions;
    public enum ListStyle
    {
        Unix,
        Windows
    }
    public class FTPLineResult
    {
        public ListStyle Style { get; set; }
        public string Name { get; set; }
        public DateTime DateTime { get; set; }
        public bool IsDirectory { get; set; }
        public long Size { get; set; }
    }
    /// <summary>
    /// from http://blogs.msdn.com/adarshk/archive/2004/09/15/230177.aspx
    /// </summary>
    public class FTPLineParser
    {
        private Regex winStyle = new Regex(@"^(?<month>\d{1,2})-(?<day>\d{1,2})-(?<year>\d{1,2})\s+(?<hour>\d{1,2}):(?<minutes>\d{1,2})(?<ampm>am|pm)\s+(?<dir>[<]dir[>])?\s+(?<size>\d+)?\s+(?<name>.*)



这篇关于如何使用C#.net获取FTP或目录中的最新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 15:36