我想要做的是添加新文件到上传列表,而旧文件正在上传。
这是上传代码和观察者:
private static void Main(string[] args)
{
//get files from local path
List<string> localFilesWithFullPath =
Directory.GetFiles(@"c:\myfiles").ToList();
foreach (var file in localFilesWithFullPath)
{
// upload each file
ftpClient.Upload("/" + Path.GetFileName(file), file);
}
Run(ftpClient, localFilesWithFullPath);
}
public static void Run(Ftp ftpClient, List<string>
localFilesWithFullPath)
{
var watcher = new FileSystemWatcher { Path = @"c:\myfiles" };
watcher.Created += (source, e) =>
{
ftpClient.Upload("/" + e.Name, e.FullPath);
};
watcher.EnableRaisingEvents = true;
Console.Read();
}
这是用于上传的FtpClass,而且效果很好。
此代码存在的问题是,旧文件在上传时完全上传 NOT 后会添加新文件,因此在上传过程中不会将新文件添加到队列中。
问:我如何使用Watcher(或其他东西)实时向上传队列添加文件?