Home Forums .NET libraries Xceed SFTP/FTP for .NET Syncronize over FTP

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21350 |

    Hi there guys

    Well as the title says, I want to syncronize a local folder with a remote folder over a ftp connection. Is this possible? I tried to look over the documentation, but can’t get any info from that. Or did I looked on wrong place? 

    Anyway, a simple code snippet will be nice to see.

    Thank you

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Lup (had 1362 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Lup,

    There is more documentation on synchronization. If you go to the main documentation page for Xceed FTP for .NET here:http://doc.xceedsoft.com/products/XceedFileSystem/. From the Table of Contents on the left side of the page, you can follow the following menu items:
    Welcome to Xceed .NET Libraries>Basic Concepts>Synchronization.

    From there, you will have access to all the documentation concerning synchronizing.

    Also find attached a basic sample application that demonstrates this.

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Michel [Xceed] (had 221 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you for your help. Can you please detail a bit as I don’t fully understand that. As I said a code snippet would be better I think. As I can get from the documentation I see there is possible but only for local to local folders. Am I correct or not?

    As I said I want a remote to local sync over FTP. So as far as I can get, I need to first call the FTP class and initialize the connection. Now how can I make the FTP connection “autodiscover” files and folders and then download them in exactly same structure on local file system?

    I know I might not be a fast learner, but any help is highly appreciated. 

    Thank you

     

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Lup (had 429 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Lup,

    I was able to find a sample that Synchronizes a local folder to a folder over FTP. Try the following:

    Visual Basic

    —————

    Dim connection As FtpConnection = New FtpConnection(m_hostAddress, m_userName, m_password)

    connection.KeepAliveInterval = intFTPKeepAlive

    Try
      Dim folder1 As AbstractFolder = New DiskFolder(strLocalFolder)
      Dim folder2 As AbstractFolder = New FtpFolder(connection, strRemoteFolder)

      Dim synOpt As New SynchronizationOptions()
      synOpt.AutoConflictResolution = True
      synOpt.AllowCreations = True
      synOpt.AllowDeletions = True
      synOpt.CompareFileData = True
      synOpt.PreviewOnly = False

      Try
        Synchronizer.EasySynchronize(folder1, folder2, synOpt)
      Catch eSynch As Exception
        AddConnectionLogInformationLine(“Synch error: {0}”, eSynch.ToString())
      End Try
    Catch ex As Exception
      AddConnectionLogInformationLine(“Exception occured: ” & ex.Message)
    Finally
      connection.CloseConnections()
    End Try

    —————

     

    C#

    —————

     

    FtpConnection connection = new FtpConnection(m_hostAddress, m_userName, m_password);
    
    connection.KeepAliveInterval = intFTPKeepAlive;
    
    try {
    	AbstractFolder folder1 = new DiskFolder(strLocalFolder);
    	AbstractFolder folder2 = new FtpFolder(connection, strRemoteFolder);
    
    	SynchronizationOptions synOpt = new SynchronizationOptions();
    	synOpt.AutoConflictResolution = true;
    	synOpt.AllowCreations = true;
    	synOpt.AllowDeletions = true;
    	synOpt.CompareFileData = true;
    	synOpt.PreviewOnly = false;
    
    	try {
    		Synchronizer.EasySynchronize(folder1, folder2, synOpt);
    	} catch (Exception eSynch) {
    		AddConnectionLogInformationLine("Synch error: {0}", eSynch.ToString());
    	}
    } catch (Exception ex) {
    	AddConnectionLogInformationLine("Exception occured: " + ex.Message);
    } finally {
    	connection.CloseConnections();
    }

    —————

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Marc [Xceed] (had 223 views)

    User (Old forums)
    Member
    Post count: 23064

    ok I appreciate the code

    however, I have another question also

    can this be done with AsyncFtpClient as I want to also be able to display data downloaded to a progress bar 

    thank you 

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Lup (had 343 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Lup,

    You do not need to use the AsyncFtpClient class in order to display downloaded data to a progress bar. In your code (before you start syncing, you can subscribe to the  OnSynchronizationProgression event in the SynchronizationEvents class. You will then have access to the Percent property from the ByteProgression property in the SynchronizationProgressionEventArgs. The event handler can look something like this:

    C#

    —————-

        /// <summary>
        /// Event handler for SynchronizationEvents SynchronizationProgression event.
        /// </summary>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        private void OnSynchronizationProgression( object sender, SynchronizationProgressionEventArgs e )
        {
          if( m_abort )
          {
            throw new AbortException( “Operation aborted” );
          }
          this.ProcessProgressBar.Value = e.ByteProgression.Percent;
          Application.DoEvents();
        }

    —————-

    You can refer to the online documentation concerning the SynchronizationEvents class found here: http://doc.xceedsoft.com/products/XceedFileSystem/Xceed.Synchronization.v5.1~Xceed.Synchronization.SynchronizationEvents_members.html for more information

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Marc [Xceed] (had 765 views)

    User (Old forums)
    Member
    Post count: 23064

    So I have added the fallowing code to my project

    (conversion to vb .net)

        Private Sub OnSynchronizationProgression(ByVal sender As Object, ByVal e As SynchronizationProgressionEventArgs)
            ProgressBar.Value = e.ByteProgression.Percent
            Application.DoEvents()
        End Sub

    Now when I click the download button, my form still freezes when the download is in progress 

    is something that I do wrong?

    Applies to Xceed FTP for .NET. Imported from legacy forums. Posted by Lup (had 1728 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.