根据从SFTP修改的日期下载文件 [英] Download file based on date modified from SFTP
问题描述
是否有一种方法可以使用Tamir.SharpSsh从SFTP服务器获取基于修改日期的文件?目前,我正在按文件名下载文件,但我的要求是按修改日期"进行.
Is there a way to get the files from SFTP server that should be based on modified date using Tamir.SharpSsh? Currently I am downloading files by file name but my requirement is by Date Modified.
var sftp = new Sftp(Host, UserName, Password);
sftp.Connect();
sftp.Get(sourcePath+"/*.*." + name + "*", destinationPath);
推荐答案
SharpSsh不允许这样做.这是一个死项目,请不要使用它.
SharpSsh does not allow that. It's a dead project, do not use it.
无论如何,我看了一下代码,以评估使用 Sftp.GetFileList
(因为该库是开源的)来检索文件时间戳的可能性有多困难.
Anyway, I took a look at the code to assess how difficult it would be add possibility to retrieve file timestamp using the Sftp.GetFileList
(since the library is open source).
您将必须:
- 将时间戳字段添加到
ChannelSftp.LsEntry
- 将解析代码的时间戳从
SSH_FXP_NAME
数据包添加到ChannelSftp.ls
方法 - 修改(或添加替代方法)
Sftp.GetFileList
不仅返回文件名,还返回时间戳(和其他文件元数据).
- Add a timestamp field to the
ChannelSftp.LsEntry
- Add parsing out timestamp from the
SSH_FXP_NAME
packet to theChannelSftp.ls
method - Modify (or add an alternative to) the
Sftp.GetFileList
to return not only file name, but also the timestamp (and other file metadata).
或者,您可以使用 WinSCP .NET程序集.您可以将其 Session.GetFiles
方法与文件掩码.例如.文件掩码 *> 7D
选择上周修改的所有文件.
Alternatively, you can use WinSCP .NET assembly. You can use its Session.GetFiles
method with a file mask. E.g. a file mask *>7D
selects all files modified in the last week.
(我是WinSCP的作者)
这篇关于根据从SFTP修改的日期下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!