我试图使用WinSCP库创建FTP Watcher,因此我可以检测添加到特定路径的每个新文件或目录,但是如果上传当前文件/目录已经完成,则不会!
示例:
session.Open(sessionOptions);
List < string > prevFiles = null;
while (true) {
// Collect file list
List < string > files =
session.EnumerateRemoteFiles(
remotePath, "*.*", EnumerationOptions.AllDirectories)
.Select(fileInfo => fileInfo.)
.ToList();
if (prevFiles == null) {
// In the first round, just print number of files found
Console.WriteLine("Found {0} files", files.Count);
} else {
// Then look for differences against the previous list
IEnumerable < string > added = files.Except(prevFiles);
if (added.Any()) {
Console.WriteLine("Added files:");
foreach(string path in added) {
Console.WriteLine(path);
}
}
}
prevFiles = files;
Console.WriteLine("Sleeping 10s...");
Thread.Sleep(10000);
}
所以我的问题是如何检测文件的上传是否已经完成,而不是在ftp服务器中添加新文件的开始。