Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
FTP Upload with Heartbeat Events, Abort, and Transfer Rate MonitoringVisual Basic 6.0 example program demonstrating FTP upload heartbeat events, abort capability, and real-time upload transfer rate monitoring. Dim WithEvents ftp As ChilkatFtp2 Dim AbortButtonPressed As Boolean Private Sub AbortButton_Click() AbortButtonPressed = True End Sub ' Upload a file with progress monitoring. Private Sub Command1_Click() AbortButtonPressed = False Set ftp = New ChilkatFtp2 success = ftp.UnlockComponent("anything for 30-day trial") If (success = 0) Then MsgBox "Failed to unlock component" Exit Sub End If ' Set our heartbeat interval to .1 seconds ' This causes ftp_AbortCheck to be called approximately every .1 seconds. ftp.HeartbeatMs = 100 ' Set the FTP hostname, login, and password. ftp.HostName = "ftp.yourftpserver.com" ftp.Username = "***" ftp.Password = "***" ' Connect and login to the FTP server. Heartbeat events fire during the ' the connection establishment, authenticaion, and during all other communications ' with the FTP server. success = ftp.Connect() If (success = 0) Then MsgBox ftp.LastErrorText Exit Sub End If ' Upload a file to the FTP server. localFile = "hamlet.xml" remoteFile = "hamlet.xml" success = ftp.PutFile(localFile, remoteFile) If (success = 0) Then MsgBox ftp.LastErrorText Exit Sub End If ftp.Disconnect MsgBox "Finished!" End Sub ' Called periodically according to the HeartbeatMs property. Private Sub ftp_AbortCheck(abort As Long) ' This example aborts the transfer if the "abort button" ' in the user interface is pressed. If AbortButtonPressed Then abort = 1 End If ' Update a progress bar so we can visually see the hearbeat. If ProgressBar2.Value = 100 Then ProgressBar2.Value = 0 Else ProgressBar2.Value = ProgressBar2.Value + 10 End If ' Display the real-time transfer rate as the upload progresses. Label1.Caption = "Bytes/Second: " & Str(ftp.UploadRate) Label1.Refresh ' Process user-interface events while waiting for the FTP transfer ' to complete. DoEvents End Sub ' Provides percentage-completion progress monitoring. Private Sub ftp_PutProgress(ByVal pctDone As Long) ProgressBar1.Value = pctDone End Sub |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.