Retrieving creation date of file (FTP)(检索文件的创建日期 (FTP))
问题描述
我正在使用 System.Net.FtpWebRequest
类,我的代码如下:
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.
我将文件夹中的所有文件名存储在 names
中,但是我现在如何遍历每个文件名并检索它们的日期?我想检索日期,以便找到最新的文件.谢谢.
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.ListDirectoryDetails
.此方法将返回 FTP 服务器上的一长串文件.将此列表检索到 names
变量后,您可以根据行尾字符将 names
变量拆分为一个数组.这将导致每个数组元素成为一个文件(或目录)名称列表,其中包括权限、上次修改日期所有者等...
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检索文件的创建日期 (FTP)


基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01