Visual Basic Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Delphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVBScript

VB Examples

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

More Examples...
Amazon S3
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 Delete Tree on FTP Server

This example is generously provided by a Chilkat customer. It deletes an entire directory tree on the remote FTP server. PS> For more FTP examples, please see the VBScript examples at http://www.example-code.com/vbscript/ftp.asp. Essentially, the only difference between VBScript and VB6 is the object creation statements.

'In globals as I do not want to keep re-creating the component!

Global ckFTP As New ChilkatFtp2

'In main function, unlock the componant.
If (ckFTP.UnlockComponent("register string") <> 1) Then

    MsgBox "FTP component error, vbOKOnly, "FTP error"
    End
End If

'Set up connection
ckFTP.Username = "username"
ckFTP.Password = "password"
ckFTP.HostName = "ftphost"
ckFTP.connect

ftpDeltree("/path/to/folder")

public function deltree(byval sBasePath string) as boolean
'sBasePath is the folder to delete. Remember to include the complete FTP path
'including the starting slash...

    Dim hFind As Long, lRet As Long
    Dim ret As Boolean
    Dim lFileCount As Long
    
    'Nasty... having to use a GOTO loop but this way, the function can recursively
    'call itself while recursive deleting.
rerun:
    
    lFileCount = 0
    'Set the current directory for the current FTP connection and find the first file/folder....
    ret = ckFTP.ChangeRemoteDir(sBasePath)
    
    '
    ' Identify and process the first file
    '
    hFind = ckFTP.NumFilesAndDirs
    
    'If there is no files or folders, delete the directory, no questions asked.
    If hFind = 0 Then
        'Delete the current directory!
        ret = ckFTP.RemoveRemoteDir(sBasePath)
        If ret = True Then
            ftpDeltree = True
            Exit Function
        Else
            ftpDeltree = False
            Exit Function
        End If
    End If
    
    'Ok, there are files and/or folders.
    'If we have a folder, call ftpDeltree with new basepath...
    
    Do While lFileCount <= hFind
    
        If ckFTP.GetIsDirectory(lFileCount) = 1 Then
            'Delete a folder
            ftpDeltree sBasePath & "/" & ckFTP.GetFilename(lFileCount)
            'Function returns. We are back in the previous context and sBasePath contains the original path.
            'Carry on now that the previous path has been deleted...
            GoTo rerun:
        Else
            'Delete a file
            'The first element found is a file and not a directory.
            'Delete the file by specifying the complete path to file with null characters in the filename trimmed off
            ret = ckFTP.DeleteRemoteFile(sBasePath & "/" & ckFTP.GetFilename(lFileCount))
        End If
        
        lFileCount = lFileCount + 1
        
    Loop
    
    ftpDeltree = True

end function

 

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