public SearchCondition SearchCondition { get; set; }
Shows how to use a custom search condition class.
using System; using ComponentPro; using ComponentPro.IO; using ComponentPro.Net; ... class CustomSearchCondition : SearchCondition { int _length; /// <summary> /// Initializes a new instance of the <see cref="CustomSearchCondition"/> class. /// </summary> public CustomSearchCondition(int fileNameLength) : base(SearchConditionFileTypes.Any) { _length = fileNameLength; } /// <summary> /// Returns a boolean value indicating whether the item matches at the search conditions. /// </summary> /// <param name="file">The <see cref="FileInfoBase"/> to check.</param> public override bool Matches(FileInfoBase file) { if (file == null) { throw new ArgumentNullException("file"); } return file.Name.Length == _length; } } private Ftp _client; public void DoUpload() { // Create a new class instance. Ftp client = new Ftp(); _client = client; // Connect to the FTP server. client.Connect("demo.componentpro.com"); // Authenticate. client.Authenticate("test", "test"); // ... client.Progress += client_Progress; try { TransferOptions opt = new TransferOptions( true, // BuildDirectoryTreeBeforeTransfer = true. true, OptionValue.Auto, new CustomSearchCondition(20), FileOverwriteMode.Overwrite, SymlinksResolveAction.Skip); // Upload all files with 20 character length in names in local folder 'c:\myfolder' to remote folder '/myfolder'. client.Upload("c:\\myfolder", "/myfolder", opt); } catch (Exception exc) { Console.WriteLine("Error: " + exc.Message); } // ... // Disconnect. client.Disconnect(); } /// <summary> /// This method is raised when user clicks on 'Cancel' button on the form. /// </summary> protected void btnCancel_Click(object sender, EventArgs e) { // Cancel the upload operation when user clicks on the button. _client.Cancel(); } void client_Progress(object sender, ComponentPro.IO.FileSystemProgressEventArgs e) { // Show progress info. Console.WriteLine("Current File: %{0} completed", e.Percentage); Console.WriteLine("Total: %{0} completed", e.TotalPercentage); switch (e.State) { case TransferState.BuildingDirectoryStructure: Console.WriteLine("Building directory structure..."); break; case TransferState.StartUploadingFile: if (e.SourcePath.EndsWith(".exe")) { // Skip all .exe files e.Skip = true; } else if (e.SourcePath.StartsWith(@"C:\MyFolder")) { // Change the source file path if it starts with "C:\MyFolder" e.SourcePath = e.SourcePath.Replace(@"C:\MyFolder", @"C:\MySecondFolder"); } break; } }
Shows how to use a custom search condition class.
using System; using ComponentPro; using ComponentPro.IO; using ComponentPro.Net; using System.Windows.Forms; ... class CustomSearchCondition : SearchCondition { int _length; /// <summary> /// Initializes a new instance of the <see cref="CustomSearchCondition"/> class. /// </summary> public CustomSearchCondition(int fileNameLength) : base(SearchConditionFileTypes.Any) { _length = fileNameLength; } /// <summary> /// Returns a boolean value indicating whether the item matches at the search conditions. /// </summary> /// <param name="file">The <see cref="FileInfoBase"/> to check.</param> public override bool Matches(FileInfoBase file) { if (file == null) { throw new ArgumentNullException("file"); } return file.Name.Length == _length; } } private Sftp _client; public void DoUpload() { // Create a new class instance. Sftp client = new Sftp(); _client = client; // Connect to the SFTP server. client.Connect("demo.componentpro.com"); // Authenticate. client.Authenticate("test", "test"); // ... client.Progress += client_Progress; try { TransferOptions opt = new TransferOptions( true, // BuildDirectoryTreeBeforeTransfer = true. true, OptionValue.Auto, new CustomSearchCondition(20), FileOverwriteMode.Overwrite, SymlinksResolveAction.Skip); // Upload all files with 20 character length in names in local folder 'c:\myfolder' to remote folder '/myfolder'. client.Upload("c:\\myfolder", "/myfolder", opt); } catch (Exception exc) { Console.WriteLine("Error: " + exc.Message); } // ... // Disconnect. client.Disconnect(); } /// <summary> /// This method is raised when user clicks on 'Cancel' button on the form. /// </summary> protected void btnCancel_Click(object sender, EventArgs e) { // Cancel the upload operation when user clicks on the button. _client.Cancel(); } void client_Progress(object sender, ComponentPro.IO.FileSystemProgressEventArgs e) { // Show progress info. Console.WriteLine("Current File: %{0} completed", e.Percentage); Console.WriteLine("Total: %{0} completed", e.TotalPercentage); switch (e.State) { case TransferState.BuildingDirectoryStructure: Console.WriteLine("Building directory structure..."); break; case TransferState.StartUploadingFile: if (e.SourcePath.EndsWith(".exe")) { // Skip all .exe files e.Skip = true; } else if (e.SourcePath.StartsWith(@"C:\MyFolder")) { // Change the source file path if it starts with "C:\MyFolder" e.SourcePath = e.SourcePath.Replace(@"C:\MyFolder", @"C:\MySecondFolder"); } break; } // Keep the form active Application.DoEvents(); }
Shows how to use a custom search condition class.
using System; using System.Collections.Generic; using System.Text; using ComponentPro; using ComponentPro.IO; using ComponentPro.Compression; using System.Windows.Forms; ... class CustomSearchCondition : SearchCondition { int _length; /// <summary> /// Initializes a new instance of the <see cref="CustomSearchCondition"/> class. /// </summary> public CustomSearchCondition(int fileNameLength) : base(SearchConditionFileTypes.Any) { _length = fileNameLength; } /// <summary> /// Returns a boolean value indicating whether the item matches at the search conditions. /// </summary> /// <param name="file">The <see cref="FileInfoBase"/> to check.</param> public override bool Matches(FileInfoBase file) { if (file == null) { throw new ArgumentNullException("file"); } return file.Name.Length == _length; } } private Zip _zip; public void DoUpload() { // Create a new instance. Zip zip = new Zip(); _zip = zip; // Open an existing archive. zip.Open("test.zip"); // ... zip.Progress += zip_Progress; try { TransferOptions opt = new TransferOptions( true, // BuildDirectoryTreeBeforeTransfer = true. true, OptionValue.Auto, new CustomSearchCondition(20), FileOverwriteMode.Overwrite, SymlinksResolveAction.Skip); // Add all files with 20 character length in names in local folder 'c:\myfolder' to remote folder '/myfolder'. zip.AddFiles("c:\\myfolder", "/myfolder", opt); } catch (Exception exc) { Console.WriteLine("Error: " + exc.Message); } // ... // Close. zip.Close(); } /// <summary> /// This method is raised when user clicks on 'Cancel' button on the form. /// </summary> protected void btnCancel_Click(object sender, EventArgs e) { // Cancel the upload operation when user clicks on the button. _zip.Cancel(); } void zip_Progress(object sender, ComponentPro.IO.FileSystemProgressEventArgs e) { // Show progress info. Console.WriteLine("Current File: %{0} completed", e.Percentage); Console.WriteLine("Total: %{0} completed", e.TotalPercentage); switch (e.State) { case TransferState.BuildingDirectoryStructure: Console.WriteLine("Building directory structure..."); break; case TransferState.StartUploadingFile: if (e.SourcePath.EndsWith(".exe")) { // Skip all .exe files e.Skip = true; } else if (e.SourcePath.StartsWith(@"C:\MyFolder")) { // Change the source file path if it starts with "C:\MyFolder" e.SourcePath = e.SourcePath.Replace(@"C:\MyFolder", @"C:\MySecondFolder"); } break; } // Keep the form active Application.DoEvents(); }