C# FileSystemWatcher And FTP

后端 未结 6 1307
南旧
南旧 2021-02-02 03:48

I monitor files that are dropped on a ftp via filesystem watcher then move to another dir. Now I trigger the copy off the create event of the filesystem watcher but obviously i

6条回答
  •  再見小時候
    2021-02-02 04:15

    When file gets copied from another server using FTP, before complete file copy , file name gets renamed with extra extension like .TMP as shown in path example below.

    C:\InterfaceServer\OilAndGas\XMLForTest\TestStbFile.xml.TMP

    To overcome this situation follow two steps

    1. When there is run of file watcher method, FileSystemEventArgs parameter contains file name with appended extra file extension to the file name as it just arrived in the folder and not completed with copy operation.
    2. You need to just call the below method to remove the extra extension and add wait for 2 seconds in the code so that the complete file gets created and you can use it for further processing.

      public static string VerifyIfStubFile(string filePath, string extension)
      {             
          if (filePath.Length - (filePath.IndexOf(extension) + extension.Length) != 0)            
          {                
              /*LogMsg("Info : VerifyIfStubFile : Stub file found. Lets fix it!!"); */               
              return filePath = filePath.Substring(0, (filePath.IndexOf(extension) + extension.Length));            
          }            
          return filePath;        
      }
      

提交回复
热议问题