FTP上传下载

FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(url));
reqFTP.Credentials = new NetworkCredential("name", "pwd");
reqFTP.Timeout = 10000;

//reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

using (FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse())
{
var st = response.GetResponseStream();
StreamReader sr = new StreamReader(st);

string line = "";

List<string> fileList = new List<string>();

do
{
try
{
line = sr.ReadLine();

if (line.Contains("xdfnews.dtd"))
{
continue;
}

var subay = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string tt = string.Format("{0} {1} {2}", subay[5], subay[6], subay[7]);
DateTime dt = DateTime.Parse(tt);
TimeSpan ts = DateTime.Now - dt;
if (Math.Abs(ts.TotalDays) > 7)
{
continue;
}

string fileName = line = line.Remove(0, line.LastIndexOf(' ') + 1);
fileName = fileName.Remove(fileName.IndexOf('.'));

string[] split = fileName.Split('-');
int num = 1;

if (split.Count() > 1)
{
num = int.Parse(split[1]);
}

if (dic.ContainsKey(split[0]))
{
fileName = Path.GetFileName(dic[split[0]]);
fileName = fileName.Remove(fileName.IndexOf('.'));

string[] sourFile = fileName.Split('-');

int dest = Convert.ToInt32(split[1]);
int source = Convert.ToInt32(sourFile[1]);
if (dest > source)
{
dic[split[0]] = line;
}

}
else
{
dic.Add(split[0], line);
}

}
catch (Exception ex)
{
HKLog.GrabError("" + ex.ToString());
}

} while (!string.IsNullOrEmpty(line))

}

posted @ 2015-09-16 14:14  Crazylight  阅读(274)  评论(0编辑  收藏  举报