VB.NET Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB.NET Examples

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

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

Byte Array
VB.NET FTPS
System.IO

 

 

 

 

 

 

Clearing the Control Channel after FTPS Authentication

Download: Chilkat .NET Assemblies

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.yourftpserver.com"
        ftp.Username = "***"
        ftp.Password = "***"

        ' 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

 

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

Mail Component · XML Parser