sftp/Module1.vb

' Technical support: support@smartftp.com

Module Module1

	Dim sshConnection As sfFTPLib.SSHConnectionClass
	Dim sftpConnection As sfFTPLib.SFTPConnectionClass

	Sub SFTPTest()
		sftpConnection = sshConnection.CreateSFTPConnection()
		'Dim fileLogger As sfFTPLib.FileLogger
		'fileLogger = sftpConnection.SetFileLogger()
		'fileLogger.File = "sftp.log"

		sftpConnection.Connect()

		Dim currentDirectory As String
		currentDirectory = sftpConnection.RealPath(".")

		' Read Directory
		Dim directoryItems As sfFTPLib.FTPItemsClass
		directoryItems = sftpConnection.ReadDirectory(currentDirectory)
		Dim item As sfFTPLib.FTPItem
		For Each item In directoryItems
			System.Console.WriteLine("Type={0}; Name={1}; Size={2}", item.Type, item.Name, item.Size)
		Next

		' Download File
		Dim startPosition As ULong
		startPosition = 0
		Dim endPosition As ULong
		endPosition = 0

		' Note: The first argument is the full path to the source file
		sftpConnection.DownloadFileEx("/History.txt", "History.txt", sfFTPLib.DataTransferType.ftpDataTransferTypeImage, startPosition, endPosition, sfFTPLib.DownloadFlags.ftpDownloadFlagReadBeyondEnd, Nothing)
		System.Console.WriteLine("DownloadFile() successful.")
		System.Console.WriteLine("LastTransferBytes = {0} B", sftpConnection.LastTransferBytes)
		System.Console.WriteLine("LastTransferTime = {0} s", sftpConnection.LastTransferTime)
		System.Console.WriteLine("LastTransferSpeed = {0} B/s", sftpConnection.LastTransferSpeed)

		' Upload file
		'sftpConnection.UploadFileEx("c:\test.dat", "/remotefolder/test.dat", sfFTPLib.DataTransferType.ftpDataTransferTypeImage, startPosition, Nothing)

	End Sub

	Sub Main()
		Dim objGlobal As sfFTPLib.[Global]
		'objGlobal = CreateObject("sfFTPLib.Global")
		objGlobal = New sfFTPLib.[Global]

		' Load License
		' If LoadLicense is not called 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: insert the provided serial after the purchase of a license
		'objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")

		'sshConnection = CreateObject("sfFTPLib.SSHConnection")
		sshConnection = New sfFTPLib.SSHConnection

		' Favorite settings
		sshConnection.Host = "localhost"
		sshConnection.Port = 22
		sshConnection.Username = "username"
		sshConnection.Password = "password"

		' Proxy settings
		'sshConnection.Proxy.Type = sfFTPLib.ProxyType.ftpProxyTypeNone

		'Dim fileLogger As sfFTPLib.FileLogger
		'fileLogger = sshConnection.SetFileLogger()
		'fileLogger.File = "ssh.log"

		sshConnection.Connect()
		SFTPTest()
		sshConnection.Disconnect()

		sshConnection = Nothing
	End Sub
End Module