ComponentPro UltimateFtp

      Synchronize files

      Language Filter: AllSend comments on this topic to ComponentPro

      To synchronize files, you can follow the steps below:

      1. Creates references to the files 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 files on an SFTP server with the local files. Files will be synchronized with the most recent files regardless of their names.

      using (Ftp client = new Ftp())
          // Connect to the FTP server. 
          // Authenticate. 
          client.Authenticate("test", "test");
          FileInfoBase masterFile = client.CreateFileInfo("/folder/myfile", true);
          FileInfoBase targetFile1 = DiskFileSystem.Default.CreateFileInfo(@"C:\temp\file1", true);
          FileInfoBase targetFile2 = DiskFileSystem.Default.CreateFileInfo(@"C:\temp\file2", true);
          Synchronizer sync = new Synchronizer();
          SyncOptions opt = new SyncOptions();
          opt.AutoConflictResolution = true;
          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 files. 
          sync.Synchronize(masterFile, opt, null, masterFile, targetFile1, targetFile2);