c# - FTPClient 将文件从 Linux 移动到 Windows。知道他们什么时候结束发电

标签 c# linux oracle ftp

<分区>

我创建了一项服务,通过 FTPClient 将文件从 Linux 计算机移动到 Windows。 LinuxComputer 中的文件由 Oracle 存储过程生成。

问题是,我不知道什么时候文件不再被写入。因为,首先 Oracle 创建一个 0kb 的文件,然后它开始写入它。我添加了一个延迟来获取文件,但这不是解决方案。

FTP 连接

   FluentFTP.FtpClient originClient = new FluentFTP.FtpClient(FTPOriginHost, FTPOriginUser, FTPOriginPass);
  originClient.Connect();
  Log.Info("FTP client is Connected.");
  originClient.GetWorkingDirectoryAsync().ContinueWith(d => Log.Info(d.Result));
  originClient.SetWorkingDirectoryAsync(FTPOriginPath).Wait();
  originClient.GetWorkingDirectoryAsync().ContinueWith(d => Log.Info(d.Result)).Wait();
  return originClient;

下载

 originClient.GetListingAsync(FTPOriginPath).ContinueWith(t =>
   {
      foreach (var item in t.Result)
      {
         originClient.DownloadFileAsync(DestinationPath + item.Name, item.FullName, true).ContinueWith(tt =>
          {
              Log.Info(item.Name + " DOWNLOAD: OK");
          }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion).Wait();
       }
   }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion).Wait();

我想将文件移动到另一个副本,以检查它是否正在复制,但是如果我在写入文件时将文件移动到 Linux 中的另一个文件夹,则移动正常,并继续写入正常另一个文件夹所以它不起作用。e

最佳答案

我通常做的是在主文件写完后创建一个空文件。空文件将与主文件同名,但具有“RDY_”后缀或“_RDY”前缀。

然后客户端将只检查这些文件,如果找到一个,传输主文件并在传输完成后删除“RDY”文件。这样,当您删除 RDY 文件时,生成这些文件的进程将不会锁定该文件。

您的下载例程必须像这样修改:

originClient.GetListingAsync(FTPOriginPath).ContinueWith(t =>
   {
      foreach (var item in t.Result)
      {
         if (item.Name.EndsWith("_RDY"))
         {
         originClient.DownloadFileAsync(DestinationPath + item.Name.Substring(0, 4), item.FullName.Substring(0, 4), true).ContinueWith(tt =>
          {
              Log.Info(item.Name.Substring(0, 4) + " DOWNLOAD: OK");
              originClient.DeleteFile(item.FullName); // of course you would have to adjust this call to the correct name of a method that deletes a file
          }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion).Wait();
         }
       }
   }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion).Wait();

当然,您还必须调整生成主文件的存储过程。

关于c# - FTPClient 将文件从 Linux 移动到 Windows。知道他们什么时候结束发电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45350628/

相关文章:

c# - 如何将一个物体的局部轴旋转到另一个物体?

oracle - URL 解码表中的一列

sql - ORACLE SQL - 如何找到每位教师在教师辞职前 2 个月每天的减免次数?

oracle - 是否可以捕获ORACLE中的语法错误

c# - 在 ItemsControl 中移动行为

c# - 同一解决方案中的不同 EntityFramework 版本

c# - 在 C#/WPF 中加速 L-System 渲染器

linux - Linux 应用程序的一个实例开始运行其自身的多个实例的可能原因是什么?

linux - 如何在 Linux 中读取 SRAM 信息?

c++ - 如何在 Linux 中将 OpenCV 添加到 LD_LIBRARY_path?