2017-07-27 134 views
1

我创建了一个服务,通过FTPClient将文件从Linux计算机移动到Windows。 LinuxComputer中的文件由Oracle商店过程生成。FTPClient将文件从Linux移动到Windows。知道它们何时结束生成

问题是,我不知道什么时候文件不再被写入。因为,首先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

+0

知道文件何时结束的唯一方法是在消息开头添加字节计数。 – jdweng

回答

1

我通常会做的是在主文件之后创建一个空文件已被写入。空文件将具有与主文件相同的名称,但具有'RDY_'后缀或'_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(); 

你会的,当然,必须调整其产生的主要文件,以及存储过程。

相关问题