文件的检索创建日期(FTP) [英] Retrieving creation date of file (FTP)

查看:129
本文介绍了文件的检索创建日期(FTP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 System.Net.FtpWebRequest 类和我的code是如下:

I'm using the System.Net.FtpWebRequest class and my code is as follows:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://example.com/folder");
request.Method = WebRequestMethods.Ftp.ListDirectory;

request.Credentials = new NetworkCredential("username", "password");

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

string names = reader.ReadToEnd();

reader.Close();
response.Close();

这是基于客提供MSDN上的例子,但我找不到任何更详细。

This is based off of the examples provided on MSDN but I couldn't find anything more detailed.

我存储的文件夹中的所有文件名中的名称但如何我现在可以通过每个那些迭代和检索他们的约会?我要检索的日期,以便我能找到最新的文件。谢谢你。

I'm storing all the filenames in the folder in names but how can I now iterate through each of those and retrieve their dates? I want to retrieve the dates so I can find the newest files. Thanks.

推荐答案

WebRequestMethods.Ftp.ListDirectory 返回所有文件的短名单中的FTP目录。这种类型的上市只会提供的文件名 - 而不是其他详细信息的文件(如权限或最后修改日期)。

WebRequestMethods.Ftp.ListDirectory returns a "short listing" of all the files in an FTP directory. This type of listing is only going to provide file names - not additional details on the file (like permissions or last modified date).

使用 WebRequestMethods.Ftp.ListDirectoryDe​​tails 来代替。该方法将返回FTP服务器上的文件的长列表。一旦检索这个列表中的名称变量,您可以变量拆分名称转换为基于一个数组行结束符。这将导致每个阵列元素是一个文件(或目录)的名称列表,其中包含的权限,上次修改日期所有者,等等...

Use WebRequestMethods.Ftp.ListDirectoryDetails instead. This method will return a long listing of files on the FTP server. Once you've retrieved this list into the names variable, you can split the names variable into an array based on an end of line character. This will result in each array element being a file (or directory) name listing that includes the permissions, last modified date owner, etc...

在这一点上,你可以通过这个数组遍历,检查每个文件的最后修改日期,并决定是否要下载的文件。

At this point, you can iterate over this array, examine the last modified date for each file, and decide whether to download the file.

我希望这有助于!

这篇关于文件的检索创建日期(FTP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆