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

Resume file download with FtpClient.ReceiveMultipleFiles

Sort Posts: Previous Next
  •  07-29-2011, 2:11 PM Post no. 30812

    Resume file download with FtpClient.ReceiveMultipleFiles

    I want to resume a file in process, that if I close the app and re-run it.

    As stated in the title, I'm using the FtpClient.ReceiveMultipleFiles method

    as sample of my code is below

    Imports Xceed.FileSystem
    Imports Xceed.Ftp
    Imports Xceed.Synchronization
    Imports System.IO
    Public Class mainGUI
        'determinari conxiune
        Dim hostname As String = "my ip"
        Dim username As String = "username"
        Dim password As String = "password"
        Public WithEvents Client As New FtpClient


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            DownloadWorker.RunWorkerAsync()
        End Sub


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

        Private Sub DownloadWorker_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles DownloadWorker.DoWork
            Client.Connect(hostname, 21)
            Client.Login(username, password)
            Client.ChangeCurrentFolder("test")
            Client.ReceiveMultipleFiles("*", Application.StartupPath & "/Download", True, True)
        End Sub

        Private Sub OnFileTransferStatus(ByVal sender As Object, ByVal e As FileTransferStatusEventArgs)
            ProgressBar.Value = e.AllBytesPercent
        End Sub

        Private Sub mainGUI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Client.SynchronizingObject = Me
            Client.PassiveTransfer = True
            Client.Timeout = "20"
            AddHandler Client.FileTransferStatus, AddressOf Me.OnFileTransferStatus
        End Sub
    End Class


    Now all runs ok, but I want to be able to resume the download in progress if I close the form and return to it later on

    How can I do this?

  •  08-09-2011, 10:37 AM Post no. 30854 in reply to 30812

    Re: Resume file download with FtpClient.ReceiveMultipleFiles

    Hi Lup,

    > Now all runs ok, but I want to be able to resume the download in progress if I close the form and return to it later on
    > How can I do this?

    Then, you shouldn't use FtpClient.ReceiveMultipleFiles(). There is no magic here:

    You should download your files one by one with FtpClient.ReceiveFile().

    Your application should track and remember each file that has been downloaded and the current one being downloaded.

    That way, if you want to resume later, you can restart downloading the last file that was downloading.

    You can also restart your download at a specific offset in the remote file with ReceiveFile() if you tracked the progress of the last downloading file before the interruption.

    ReceiveFile() flavors that support remote offsets:
    http://doc.xceedsoft.com/products/XceedFileSystem/Xceed.Ftp.v5.1~Xceed.Ftp.FtpClient~ReceiveFile(String,Int64,String,Boolean).html
    http://doc.xceedsoft.com/products/XceedFileSystem/Xceed.Ftp.v5.1~Xceed.Ftp.FtpClient~ReceiveFile(String,Int64,Stream).html

    Tracking the progress of a downloading file can be done with the FtpClient.FileTransferStatus event:

    http://doc.xceedsoft.com/products/XceedFileSystem/Xceed.Ftp.v5.1~Xceed.Ftp.FtpClient~FileTransferStatus_EV.html


    Marc

    Developer in Technical Support
    Xceed - Multi-talented components - http://xceed.com
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.