ftp/Module1.vb
Option Explicit On
Module Module1
Dim objFTP As sfFTPLib.FTPConnectionMTAClass
Sub Main()
Dim objGlobal As sfFTPLib.[Global]
'objGlobal = CreateObject("sfFTPLib.Global")
objGlobal = New sfFTPLib.[Global]
Dim strKey As String
' strKey = strKey & "-----BEGIN KEY-----" & Chr(13) & Chr(10)
' strKey = strKey & "Product: SmartFTP FTP Library" & Chr(13) & Chr(10)
' strKey = strKey & "ID: 400000000" & Chr(13) & Chr(10)
' strKey = strKey & "User: user" & Chr(13) & Chr(10)
' strKey = strKey & "Company: my company" & Chr(13) & Chr(10)
' strKey = strKey & "Email: user@host.com" & Chr(13) & Chr(10)
' strKey = strKey & "Version: 1.0" & Chr(13) & Chr(10)
' strKey = strKey & "Number of Users: 1" & Chr(13) & Chr(10)
' strKey = strKey & "Date of Issue: 2005-04-05" & Chr(13) & Chr(10)
' strKey = strKey & "Maintenance Expiration: 2006-04-05" & Chr(13) & Chr(10)
' strKey = strKey & "-----BEGIN SIGNATURE-----" & Chr(13) & Chr(10)
' strKey = strKey & "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & Chr(13) & Chr(10)
' strKey = strKey & "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & Chr(13) & Chr(10)
' strKey = strKey & "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & Chr(13) & Chr(10)
' strKey = strKey & "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" & Chr(13) & Chr(10)
' strKey = strKey & "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==" & Chr(13) & Chr(10)
' strKey = strKey & "-----END SIGNATURE-----" & Chr(13) & Chr(10)
' New license key format
strKey = ""
strKey = strKey & "<?xml version=\""1.0\"" ?>" & Chr(13) & Chr(10)
strKey = strKey & "<License>" & Chr(13) & Chr(10)
strKey = strKey & "<Version>2.0</Version>" & Chr(13) & Chr(10)
strKey = strKey & "<Id>400012345</Id>" & Chr(13) & Chr(10)
strKey = strKey & "<Name>name</Name>" & Chr(13) & Chr(10)
strKey = strKey & "<Email>user@host.com</Email>" & Chr(13) & Chr(10)
strKey = strKey & "<Company>company</Company>" & Chr(13) & Chr(10)
strKey = strKey & "<Product>SmartFTP FTP Library</Product>" & Chr(13) & Chr(10)
strKey = strKey & "<Features>" & Chr(13) & Chr(10)
strKey = strKey & "<Feature>SFTP</Feature>" & Chr(13) & Chr(10)
strKey = strKey & "</Features>" & Chr(13) & Chr(10)
strKey = strKey & "<Users>1</Users>" & Chr(13) & Chr(10)
strKey = strKey & "<Maintenance>2008-12-27</Maintenance>" & Chr(13) & Chr(10)
strKey = strKey & "<Issue>2007-12-27</Issue>" & Chr(13) & Chr(10)
strKey = strKey & "<Signature>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>" & Chr(13) & Chr(10)
strKey = strKey & "</License>" & Chr(13) & Chr(10)
' Load License Key
If objGlobal.LoadLicenseKeyData(strKey) Then
System.Console.WriteLine("License key verified.")
Else
System.Console.WriteLine("Failed to verify license key.")
End If
Dim objUPnP As sfFTPLib.UPnPNATManager
objUPnP = New sfFTPLib.UPnPNATManager
objUPnP.Initialize()
'objFTP = CreateObject("sfFTPLib.FTPConnectionMTA")
objFTP = New sfFTPLib.FTPConnectionMTA
' Attach the event handler
AddHandler objFTP.OnConnect, AddressOf OnConnect
AddHandler objFTP.OnTransferProgress, AddressOf OnTransferProgress
' Favorite settings
objFTP.Host = "ftp.smartftp.com"
objFTP.Port = 21
objFTP.Protocol = sfFTPLib.enumProtocol.ftpProtocolSSLExplicit
objFTP.Username = "anonymous"
objFTP.Password = "test@test.com"
objFTP.MLST = True
objFTP.Passive = True
' Proxy settings
objFTP.ProxyType = sfFTPLib.enumProxyType.ftpProxyTypeNone
objFTP.FTPProxyType = sfFTPLib.enumFTPProxyType.ftpFTPProxyTypeNone
objFTP.LogFile = "VBDemo.log"
If objFTP.Connect() = sfFTPLib.enumError.ftpErrorSuccess Then
' Change Directory
If objFTP.ChangeDirectory("/SmartFTP") = sfFTPLib.enumError.ftpErrorSuccess Then
' Read Directory
If objFTP.ReadDirectory() = sfFTPLib.enumError.ftpErrorSuccess Then
Dim objDirectory As sfFTPLib.FTPItemsClass
objDirectory = objFTP.Items
Dim objItem As sfFTPLib.FTPItem
For Each objItem In objDirectory
System.Console.WriteLine("Type={0}; Name={1}; Size={2}", objItem.Type, objItem.Name, objItem.Size)
Next
Else
System.Console.WriteLine("ReadDirectory()failed. LastError = {0}", objFTP.LastError)
End If
' Download File
Dim nRestartLo As System.UInt32
Dim nRestartHi As System.UInt32
' Convert value to UInt32
nRestartLo = System.Convert.ToUInt32(0)
nRestartHi = System.Convert.ToUInt32(0)
If objFTP.DownloadFile("History.txt", "History.txt", nRestartLo, nRestartHi) = sfFTPLib.enumError.ftpErrorSuccess Then
System.Console.WriteLine("DownloadFile() successful.")
System.Console.WriteLine("LastTransferBytes = {0} B", objFTP.LastTransferBytes)
System.Console.WriteLine("LastTransferTime = {0} s", objFTP.LastTransferTime)
System.Console.WriteLine("LastTransferSpeed = {0} B/s", objFTP.LastTransferSpeed)
Else
System.Console.WriteLine("DownloadFile() failed. LastError = {0}", objFTP.LastError)
System.Console.WriteLine("LastReplyCode = {0}", objFTP.LastReplyCode)
System.Console.WriteLine("LastReply = {0}", objFTP.LastReply)
End If
Else
System.Console.WriteLine("ChangeDirectory() failed. LastError = {0}", objFTP.LastError)
End If
objFTP.Disconnect()
Else
If objFTP.LastError = sfFTPLib.enumError.ftpErrorLicense Then
System.Console.WriteLine("Please acquire a license from http://www.smartftp.com")
Else
System.Console.WriteLine("Connect() failed. LastError = {0}", objFTP.LastError)
End If
End If
objUPnP.Uninitialize()
objFTP = Nothing
End Sub
Sub OnConnect()
System.Console.WriteLine("OnConnect()")
End Sub
Sub OnTransferProgress(ByVal nLo As System.Int32, ByVal nHi As System.Int32)
System.Console.WriteLine("OnTransferProgress(""{0}"")", objFTP.LastTransferBytes)
End Sub
End Module