Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

FTP Download with Heartbeat Events, Abort, and Transfer Rate Monitoring

Download Chilkat FTP2 ActiveX

Visual Basic 6.0 example program FTP heartbeat events, abort cabability, and real-time data rate monitoring.

Dim WithEvents ftp As ChilkatFtp2
Dim AbortButtonPressed As Boolean

Private Sub AbortButton_Click()
    AbortButtonPressed = True
End Sub

' Download 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

    'Some FTP server may require that the AutoGetSizeForProgress property be set to true.
    ftp.AutoGetSizeForProgress = 1
       
    ' Download a file from the FTP server.
    localFile = "hamlet.xml"
    remoteFile = "hamlet.xml"
    success = ftp.GetFile(remoteFile, localFile)
    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 download progresses.
    Label1.Caption = "Bytes/Second: " & Str(ftp.DownloadRate)
    Label1.Refresh
    
    ' Process user-interface events while waiting for the FTP transfer
    ' to complete.
    DoEvents
    
End Sub

' Provides download percentage-completion progress monitoring.
Private Sub ftp_GetProgress(ByVal pctDone As Long)
    ProgressBar1.Value = pctDone
End Sub



© 2000-2010 Chilkat Software, Inc. All Rights Reserved.