VB.NET Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



VB.NET Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
PFX
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression
Misc

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Byte Array
VB.NET FTPS
System.IO

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

Clearing the Control Channel after FTPS Authentication

VB.NET sample program discussing FTPS and while clearing the control channel may be necessary.

    ' Clearing the Control Channel after FTPS Authentication
    ' 
    ' This example explains why the FTP control channel (in many cases) 
    ' must revert to unencrypted transmissions in order to do secure FTP
    ' data transfers.
    ' 
    ' The control channel must be cleared (i.e. revert to non-encrypted) when
    ' (1) the FTP server is behind a firewall such that only Active transfers
    ' are allowable (FTP Passive mode does not work), and (2) your FTP client
    ' is behind a router that performs NAT (Network Address Translation), which 
    ' is the default for DSL/Cable routers.  
    '
    ' When doing a data transfer in Active mode, the FTP client sends a PORT command
    ' to the FTP server with the IP address and port number where the client is
    ' listening for the data connection from the server.  If the FTP client is
    ' on a local area network behind a router, the IP address is local (i.e. something
    ' like 192.168.1.5).  The router is FTP-protocol-aware and translates the 
    ' IP address in the PORT command to an external/static IP address and port.  
    ' However, if the control connection is encrypted, the router cannot translate
    ' the contents of the PORT command.  (The router cannot parse any of the FTP
    ' protocol because it is encrypted.)  
    ' 
    ' The FTP control channel is cleared *after* authentication.  All FTP commands
    ' are sent unencrypted, but data transfer channels remain encrypted.
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        ' The most common method of doing secure FTP file transfers is
        ' by AUTH TLS (also known as AUTH SSL).
        ' The client connects on the standard unencrypted FTP port 21
        ' and then issues an "AUTH TLS" command to convert the TCP/IP control channel
        ' to a TLS encrypted channel.  All communications from that point onward,
        ' including data transfers, are encrypted (unless the control channel
        ' is cleared).

        Dim ftp As New Chilkat.Ftp2
        Dim success As Boolean

        success = ftp.UnlockComponent("Anything for 30-day trial")
        If (Not success) Then
            MessageBox.Show(ftp.LastErrorText)
            Exit Sub
        End If

        ' Set the AuthTls property = true.
        ftp.AuthTls = True

        ' Leave the Ssl property false.  The Ssl property is used
        ' for doing Secure FTP over SSL on port 990 (implicit SSL)
        ' FTP Implicit SSL is covered in another example.
        ftp.Ssl = False

        ' Set the FTP hostname, login, and password.
        ftp.Hostname = "ftp.akronbackups.com"
        ftp.Username = "web0041"
        ftp.Password = "***"

        ' Note: Chilkat would like to thank Akron Backups 
        ' (http://www.akronbackups.com) for their help
        ' in providing FTP servers for testing.
        ' 
        ' In addition to their online backup service, Akron Backups
        ' offers a free 100MB FTP account: http://www.akronbackups.com/subscribe.html
        ' It uses the Serv-U FTP server: http://www.serv-u.com/
        ' This is a *great* way to test your FTP and Secure FTP applications
        ' using an offsite FTP server located elsewhere on the Internet (i.e.
        ' not on your local area network).

        ' Session logging is not required, but I'm turning it on here to see
        ' what transpires during the FTP session.  The session log provides the
        ' unencrypted FTP requests and responses.
        ftp.KeepSessionLog = True

        ' Connect and login to the FTP server.  This establishes a control connection
        ' to the FTP server (port 21), converts the channel to TLS (because AuthTls is true),
        ' and then authenticates.
        success = ftp.Connect()
        If (Not success) Then
            MessageBox.Show(ftp.LastErrorText)
            Exit Sub
        End If

        ' This is how you clear the control channel:
        success = ftp.ClearControlChannel()
        If (Not success) Then
            MessageBox.Show(ftp.LastErrorText)
            Exit Sub
        End If

        ' Upload a file.
        Dim localFilename As String
        Dim remoteFilename As String
        localFilename = "hamlet.xml"
        remoteFilename = "hamlet.xml"

        ' Upload a file over an encrypted data transfer channel.
        success = ftp.PutFile(localFilename, remoteFilename)
        If (Not success) Then
            MessageBox.Show(ftp.LastErrorText)
            Exit Sub
        End If

        ' You may examine the LastErrorText even when successful
        ' to review the details of the file transfer.  You can verify
        ' that the file was transferred over a secure channel:
        MessageBox.Show(ftp.LastErrorText)

        ' Download a file.
        localFilename = "hamletDownloaded.xml"

        success = ftp.GetFile(remoteFilename, localFilename)
        If (Not success) Then
            MessageBox.Show(ftp.LastErrorText)
            Exit Sub
        End If

        ' Disconnect
        ftp.Disconnect()

        ' Display the session log
        TextBox1.Text = ftp.SessionLog

    End Sub

 

Need a specific example? Send a request to support@chilkatsoft.com

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

Mail Component · XML Parser