ComponentPro UltimateFtp

      Synchronize directories

      Language Filter: AllSend comments on this topic to ComponentPro

      To synchronize directories, you can follow the steps below:

      1. Creates references to the directories that will be synchronized
      2. Create a new instance of the Synchronizer class
      3. Call the Synchronize method

      The following example demonstrates how to synchronize directories on an FTP server with the local directories. Files within the directories will be synchronized with the most recent version of the correspondingly named file.

      using (Ftp client = new Ftp())
      {
          // Connect to the FTP server. 
          client.Connect("localhost");
      
          // Authenticate. 
          client.Authenticate("test", "test");
      
          FileInfoBase masterFolder = client.CreateFileInfo("/myfolder", false);
          FileInfoBase targetFolder1 = DiskFileSystem.Default.CreateFileInfo(@"C:\temp\folder1", false);
          FileInfoBase targetFolder2 = DiskFileSystem.Default.CreateFileInfo(@"C:\temp\folder2", false);
      
          Synchronizer sync = new Synchronizer();
          SyncOptions opt = new SyncOptions();
          opt.AutoConflictResolution = true;
          opt.AllowCreations = true;
          opt.AllowDeletions = false; // Dont allow deletions. 
          opt.TimeResolution = TimeResolution.Seconds;
      
          // Set the Time zone offset between the FTP server and the client 
          // Let assume that the time offset is 12 hours.  
          // or you can call client.GetServerTimeDifference() to get the time difference. 
          client.ServerTimeZoneOffset = new TimeSpan(0, 12, 0, 0);
      
          // Synchronize directories. 
          sync.Synchronize(masterFolder, opt, null, masterFolder, targetFolder1, targetFolder2);
      }