public class FileChecksumComparer : IoFileComparer
Shows how to use FileComparers.FileChecksumComparer for synchronizing a local folder with a remote folder.
using ComponentPro.IO; using ComponentPro.Net; ... // Create a new class instance. Ftp client = new Ftp(); // Connect to the FTP server. client.Connect("myserver"); // Authenticate. client.Authenticate("userName", "password"); // Create a new instance of the MirrorOptions class. QuickSyncOptions opt = new QuickSyncOptions(); // Set synchronization's settings // Synchronize files that are different in checksum. // Files with the same SHA1 computed checksum will not be synchronized. opt.Comparer = FileComparers.FileSha1ChecksumComparer; opt.Recursive = true; // Synchronize folders. client.QuickSynchronize( "", // Source directory path within the archive. "" indicates the current remote directory on the server. "c:\\test", // Destination directory path. true, // Source directory is master. It means "c:\test" will be identical to the current remote directory. opt ); // Synchronize files that are different in contents. opt.Comparer = FileComparers.FileSha1ChecksumComparer; opt.Recursive = true; // Synchronize folders. client.QuickSynchronize( "", // Source directory path within the archive. "" indicates the current remote directory on the server. "c:\\test2", // Destination directory path. true, // Source directory is master. It means "c:\test2" will be identical to the current remote directory. opt ); // That comparer can also be used in Upload and Download operations. TransferOptions transferOptions = new TransferOptions(); // Files with the same checksum will not be downloaded. transferOptions.Comparer = FileComparers.FileSha1ChecksumComparer; transferOptions.FileOverwriteMode = FileOverwriteMode.CustomCompare; // Download .txt files from the current remote directory. Only files with different checksum will be downloaded. client.Download("*.txt", "C:\\temp", transferOptions); // Close the connection. client.Disconnect();
Shows how to use FileComparers.FileChecksumComparer for synchronizing a local folder with a remote folder.
using ComponentPro.IO; using ComponentPro.Net; ... // Create a new class instance. Sftp client = new Sftp(); // Connect to the SFTP server. client.Connect("myserver"); // Authenticate. client.Authenticate("userName", "password"); // Create a new instance of the MirrorOptions class. QuickSyncOptions opt = new QuickSyncOptions(); // Set synchronization's settings // Synchronize files that are different in checksum. // Files with the same SHA1 computed checksum will not be synchronized. opt.Comparer = FileComparers.FileSha1ChecksumComparer; opt.Recursive = true; // Synchronize folders. client.QuickSynchronize( "", // Source directory path within the archive. "" indicates the current remote directory on the server. "c:\\test", // Destination directory path. true, // Source directory is master. It means "c:\test" will be identical to the current remote directory. opt ); // Synchronize files that are different in contents. opt.Comparer = FileComparers.FileSha1ChecksumComparer; opt.Recursive = true; // Synchronize folders. client.QuickSynchronize( "", // Source directory path within the archive. "" indicates the current remote directory on the server. "c:\\test2", // Destination directory path. true, // Source directory is master. It means "c:\test2" will be identical to the current remote directory. opt ); // That comparer can also be used in Upload and Download operations. TransferOptions transferOptions = new TransferOptions(); // Files with the same checksum will not be downloaded. transferOptions.Comparer = FileComparers.FileSha1ChecksumComparer; transferOptions.FileOverwriteMode = FileOverwriteMode.CustomCompare; // Download .txt files from the current remote directory. Only files with different checksum will be downloaded. client.Download("*.txt", "C:\\temp", transferOptions); // Close the connection. client.Disconnect();
Shows how to use FileComparers.FileChecksumComparer for synchronizing a local folder with a remote folder.
using ComponentPro.Compression; using ComponentPro.IO; using ComponentPro.Net; ... // Create a new class instance. using (Zip arc = new Zip()) { arc.Open("myzip.zip"); // Create a new instance of the QuickSyncOptions class. QuickSyncOptions opt = new QuickSyncOptions(); // Set synchronization's settings // Synchronize files that are different in checksum. // Files with the same SHA1 computed checksum will not be synchronized. opt.Comparer = FileComparers.FileSha1ChecksumComparer; opt.Recursive = true; // Synchronize folders. arc.QuickSynchronize( "", // Source directory path within the archive. "" indicates the current directory within the archive. "c:\\test", // Destination directory path. true, // Source directory is master. It means "c:\test" will be identical to the directory within the archive. opt ); // Synchronize files that are different in contents. opt.Comparer = FileComparers.FileSha1ChecksumComparer; opt.Recursive = true; // Synchronize folders. arc.QuickSynchronize( "", // Source directory path within the archive. "" indicates the current directory within the archive. "c:\\test2", // Destination directory path. true, // Source directory is master. It means "c:\test2" will be identical to the directory within the archive. opt ); // That comparer can also be used in UploadFiles and DownloadFiles operations. TransferOptions transferOptions = new TransferOptions(); // Files with the same checksum will not be extracted. transferOptions.Comparer = FileComparers.FileSha1ChecksumComparer; transferOptions.FileOverwriteMode = FileOverwriteMode.CustomCompare; // Extract .txt files from the current archive directory. Only files with different checksum will be extracted. arc.ExtractFiles("*.txt", "C:\\temp", transferOptions); }