【问题标题】:Is there a way to only get files in a date range over FTP? [duplicate]有没有办法只通过 FTP 获取某个日期范围内的文件? [复制]
【发布时间】:2020-05-28 13:54:33
【问题描述】:

我们每天都有一个同步过程,以确保我们拥有来自远程 SFTP 的所有文件,但随着时间的推移,我们不得不下载所有文件,只是为了检查我们是否已经按内容在数据库中归档了副本哈希。

有没有办法,比如使用SSH.NETWinSCP,只对过去两周内的文件执行此过程?

【问题讨论】:

标签: c# .net ftp sftp winscp-net


【解决方案1】:

我会使用FluentFTP

using FluentFTP;
using System.Linq;

.
.
.

DateTime min = ...;
DateTime max = ...;

using (var conn = new FtpClient("address", "user", "password"))
{
    conn.Connect();

    var files = conn
        .GetListing("/path", FtpListOption.Recursive)
        .Where(item => item.Type == FtpFileSystemObjectType.File
                    && item.Modified >= min
                    && item.Modified <= max);

    foreach(var file in files)
    {
        ...
    }
}

您可以使用Created 代替Modified

【讨论】:

  • 虽然 OP 对 SFTP 和 FTP 术语的使用确实有点不一致,但我相信他实际上想使用 SFTP,而不是 FTP。所以 FluentFTP 无济于事。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-07
  • 1970-01-01
  • 2011-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多