Download file based on date modified from SFTP

蹲街弑〆低调 提交于 2019-12-18 18:03:21

问题


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

回答1:


SharpSsh does not allow that. It's a dead project, do not use it.

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

You would have to:

  • Add a timestamp field to the ChannelSftp.LsEntry
  • Add parsing out timestamp from the SSH_FXP_NAME packet to the ChannelSftp.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).

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.

(I'm the author of WinSCP)




回答2:


SFTP protocol doesn't let you specify the filemask for the operation. Processing of the mask you pass is done on the client side anyway. So you can only list all files, then traverse the list and pick the files you need by certain criteria.



来源:https://stackoverflow.com/questions/25543826/download-file-based-on-date-modified-from-sftp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!