我需要使用 SSIS 中的 C# 和脚本任务从 SFTP 站点下载压缩文件。
我们在服务器上有多个文件,名称相同,但日期和时间戳不同。
有没有办法根据最近的日期和时间戳下载文件?
正如@MarkSinkinson的回答所示,您可以使用WinSCP .NET assembly。
WinSCP 站点上有一个用于下载最新文件的官方示例。
如图所示,要选择并下载最新的文件,请使用:
// Get list of files in the directory
RemoteDirectoryInfo directoryInfo = session.ListDirectory(remotePath);
// Select the most recent file
RemoteFileInfo latest =
directoryInfo.Files
.Where(file => !file.IsDirectory)
.OrderByDescending(file => file.LastWriteTime)
.FirstOrDefault();
// Any file at all?
if (latest == null)
{
throw new Exception("No file found");
}
// Download the selected file
session.GetFiles(RemotePath.EscapeFileMask(remotePath + latest.Name), localPath).Check();
Run Code Online (Sandbox Code Playgroud)
有关完整代码,请参阅链接。
另请参阅有关使用 SSIS 中的 WinSCP .NET 程序集的文章。
(我是 WinSCP 的作者)
| 归档时间: |
|
| 查看次数: |
5903 次 |
| 最近记录: |