Home Forums .NET libraries Xceed SFTP/FTP for .NET Resume file download with FtpClient.ReceiveMultipleFiles

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

    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?

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

    Xceed Support
    Member
    Post count: 5658

    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

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

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