ftp/Module1.vb
' Technical support: support@smartftp.com
Module Module1
Dim ftpConnection As sfFTPLib.FTPConnectionMTA
Sub Main()
Dim ftplibGlobal = New sfFTPLib.[Global]
' If LoadLicense Is not called, the component reads the product key from the Windows registry.
' The product key can be set using the supplied SetProductKey.cmd script from the installation folder.
' If no product key Is found in the registry, e.g. during the trial period, a trial license Is automatically obtained
' from the activation server.
'
' The FTP Library uses WinHTTP to access the activation server at www.smartftp.com (TLS, port 443).
' Ensure that your application Is Not blocked by any firewall.
'
' TODO: For manual activation, use the provided product key after purchasing a license.
'ftplibGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
ftpConnection = New sfFTPLib.FTPConnectionMTA
' Attach the event handler
AddHandler ftpConnection.OnDisconnect, AddressOf OnDisconnect
' Favorite settings
ftpConnection.Host = "ftp.smartftp.com"
' 21 is the default value
'ftpConnection.Port = 21
ftpConnection.Protocol = sfFTPLib.FTPProtocol.ftpProtocolPreferTLS
ftpConnection.Username = "anonymous"
ftpConnection.Password = "test@test.com"
'ftpConnection.Passive = True
' if the FTP server (e.g. Microsoft FTP Service for IIS with virtual hosts) requires the HOST command, uncomment this line
'ftpConnection.FEAT = sfFTPLib.FEATCommand.ftpFEATCommandEnableBeforeAndAfterLogin
' Proxy settings
'ftpConnection.Proxy.Type = sfFTPLib.ProxyType.ftpProxyTypeNone
Dim fileLogger = ftpConnection.SetFileLogger()
fileLogger.file = "VBDemo.log"
ftpConnection.Connect()
ftpConnection.ChangeDirectory("/")
Dim directoryItems = ftpConnection.ReadDirectory()
Dim item As sfFTPLib.FTPItem
For Each item In directoryItems
If item.Type = sfFTPLib.ItemType.ftpItemTypeRegularFile Then
System.Console.WriteLine("Type={0}; Name={1}; Size={2}", item.Type, item.Name, item.Size)
Else
System.Console.WriteLine("Type={0}; Name={1}", item.Type, item.Name)
End If
Next
' Download File
Dim startPosition As ULong = 0
Dim endPosition As ULong = ULong.MaxValue
ftpConnection.DownloadFileEx("This is a DEMO server.txt", "This is a DEMO server.txt", startPosition, endPosition, Nothing)
System.Console.WriteLine("DownloadFile() successful.")
System.Console.WriteLine("LastTransferBytes = {0} B", ftpConnection.LastTransferBytes)
System.Console.WriteLine("LastTransferTime = {0} s", ftpConnection.LastTransferTime)
System.Console.WriteLine("LastTransferSpeed = {0} B/s", ftpConnection.LastTransferSpeed)
' Upload file
'ftpConnection.UploadFileEx("c:\test.dat", "test.dat", startPosition, Nothing);
ftpConnection.Disconnect()
ftpConnection = Nothing
End Sub
Sub OnDisconnect()
System.Console.WriteLine("OnDisconnect")
End Sub
End Module