码迷,mamicode.com
首页 > Web开发 > 详细

FTP上传下载

时间:2015-09-16 15:27:48      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

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))

}

FTP上传下载

标签:

原文地址:http://www.cnblogs.com/crazylight/p/4813208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!