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 UploadDownload: Chilkat .NET Assemblies VB.NET example code showing how to upload in a background thread, monitor the progress, an abort if necessary. ' Asynchronous FTP Upload Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.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 upload in a background thread: Dim localFilename As String Dim remoteFilename As String localFilename = "hamlet.xml" remoteFilename = "hamlet.xml" success = ftp.AsyncPutFileStart(localFilename, remoteFilename) 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 upload 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.UploadRate) Label1.Refresh() Label2.Text = "Bytes Received: " & Convert.ToString(ftp.AsyncBytesSent) Label2.Refresh() ' The upload can be aborted at any time by calling AsyncAbort If AbortButtonPressed Then ftp.AsyncAbort() End If End While ' The upload 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 Upload Finished!") End Sub |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.