Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Secure FTP (FTPS) using AUTH TLSVB.NET example program showing how to do secure FTP upload and download (FTPS). ' Secure FTP (FTPS) using AUTH TLS
'
' What is TLS?
' Transport Layer Security (TLS) is the successor to
' Secure Sockets Layer (SSL). It is a cryptographic protocol that
' provides secure communications on the Internet for such things as
' email, FTP, and other data transfers. There are slight differences
' between SSL 3.0 and TLS 1.0, but the protocols are substantially the
' same.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.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 channel
' to a TLS encrypted channel. All communications from that point onward,
' including data transfers, are encrypted.
' This VB.NET FTPS example shows to how do secure FTP uploads and
' downloads using AUTH TLS.
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 establishs 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
' You may need to clear the control channel if your FTP client
' is located behind a network-address-translating router
' such as with a Cable/DSL router.
'ftp.ClearControlChannel()
' Upload a file.
Dim localFilename As String
Dim remoteFilename As String
localFilename = "hamlet.xml"
remoteFilename = "hamlet.xml"
' Note: if PutFile fails and you get this in your LastErrorText:
' PortReply: 530 Only client IP address allowed for PORT command.
' It indicates that you must first clear the control channel
' because your FTP client sits behind a router doing NAT (network
' address translation). The router is not able to translate the
' IP address in the PORT command if the control channel is encrypted.
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
This program produces the following session log:
220 Welcome to Akron Archives Backup Server - Authorized Accounts Only
.
AUTH TLS
234 AUTH command OK. Initializing SSL connection.
.
PBSZ 0
200 PBSZ command OK. Protection buffer size set to 0.
.
PROT P
200 PROT command OK. Using private data connection.
.
USER web0041
331 User name okay, need password.
.
PASS ****
230 User logged in, proceed.
.
TYPE I
200 Type set to I.
.
CCC
200 Command channel switched to clear-text.
.
PORT 192,168,1,100,4,150
200 PORT Command successful.
.
STOR hamlet.xml
150 Opening BINARY mode data connection for hamlet.xml.
226-Maximum disk quota limited to 512000 kBytes
Used disk quota 218923 kBytes, available 293076 kBytes
226 Transfer complete.
.
PORT 192,168,1,100,4,152
200 PORT Command successful.
.
RETR hamlet.xml
150 Opening BINARY mode data connection for hamlet.xml (279658 Bytes).
226-Maximum disk quota limited to 512000 kBytes
Used disk quota 218923 kBytes, available 293076 kBytes
226 Transfer complete.
.
QUIT
221 Goodbye!
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.