Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Asynchronous FTP DownloadDownload: Chilkat .NET Assemblies VB.NET example program showing how to download in a background thread, monitor the progress, an abort if necessary. ' Simple example to do an asynchronous FTP download in a background thread.
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim success As Boolean
Dim ftp As New Chilkat.Ftp2()
success = ftp.UnlockComponent("Anything for 30-day trial")
If (Not success) Then
MessageBox.Show("Component not unlocked")
Exit Sub
End If
' Set the FTP hostname, login, and password.
ftp.Hostname = "ftp.***.com"
ftp.Username = "***"
ftp.Password = "***"
' Connect and login to the FTP server.
success = ftp.Connect()
If (Not success) Then
MessageBox.Show(ftp.LastErrorText)
Exit Sub
End If
' Begin the download.
success = ftp.AsyncGetFileStart("XmpSpecification.pdf", "xmpSpec.pdf")
If (Not success) Then
MessageBox.Show(ftp.LastErrorText)
Exit Sub
End If
' This is where your application might do other interesting tasks...
' This example will loop and update the current download rate and bytes
' transferred.
While Not ftp.AsyncFinished
System.Threading.Thread.Sleep(100)
' Handle application events so our user interface remains responsive.
Application.DoEvents()
' Update label controls with the current data rate and # bytes downloaded.
Label1.Text = "Bytes/Second: " & Convert.ToString(ftp.DownloadRate)
Label1.Refresh()
Label2.Text = "Bytes Received: " & Convert.ToString(ftp.AsyncBytesReceived)
Label2.Refresh()
' The download can be aborted at any time by calling AsyncAbort
If AbortButtonPressed Then
ftp.AsyncAbort()
End If
End While
' The download is finished, now check the success:
If Not ftp.AsyncSuccess Then
MessageBox.Show(ftp.AsyncLog)
End If
' Disconnect
ftp.Disconnect()
' We're finished!
MessageBox.Show("FTP Async Download Finished!")
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.