Welcome to the Xceed Community | Help
Community Search  
More Search Options

Syncronize over FTP

Sort Posts: Previous Next
  •  07-23-2011, 3:32 PM Post no. 30775

    Syncronize over FTP

    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

  •  07-23-2011, 5:04 PM Post no. 30776 in reply to 30775

    Re: Syncronize over FTP

    Attachment: Synchronize.zip

    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.


    Best Regards,

    Michel Dahdah
    Technical Support
    Xceed Software inc.
  •  07-24-2011, 11:49 AM Post no. 30779 in reply to 30776

    Re: Syncronize over FTP

    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

     

  •  07-25-2011, 12:53 PM Post no. 30781 in reply to 30779

    Re: Syncronize over FTP

    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();
    }

    ---------------


    Marc

    Developer in Technical Support
    Xceed - Multi-talented components - http://xceed.com
  •  07-25-2011, 1:15 PM Post no. 30782 in reply to 30781

    Re: Syncronize over FTP

    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 

  •  07-25-2011, 1:40 PM Post no. 30783 in reply to 30782

    Re: Syncronize over FTP

    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


    Marc

    Developer in Technical Support
    Xceed - Multi-talented components - http://xceed.com
    Filed under: ,
  •  07-25-2011, 4:03 PM Post no. 30784 in reply to 30783

    Re: Syncronize over FTP

    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?

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.