' **
' Just a simple Sample setting Transfer Speed DYNAMICLY on an ASYNCRON task
' Realized with the "KellermanSoftware LIB"
' **
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Net
Imports System.IO
Imports KellermanSoftware.NetSFtpLibrary
Imports Microsoft.Win32
Imports KellermanSoftware.NetSFtpLibrary.Interfaces
Module Module1

    Sub Main()
        Dim TimeStatus As String
        Dim TimeStatusOld As String
        Dim TheTime As DateTime
        Dim DaySpeed As Int16
        Dim NightSpeed As Int16
        TimeStatus = ""
        TimeStatusOld = ""
        DaySpeed = 2048
        NightSpeed = 0


        ' *!! Trial Mode: 30 day Trial -> For permanent use a Licence needs to be purchased          
		Dim sftp As SFTP = New SFTP()
        sftp.HostAddress = "RemoteHost"
        sftp.SshKeyFile = "Path to KeyFile"
        sftp.Port = Port
        sftp.UserName = "Username"
        sftp.EnableLogging()
        sftp.Connect()

        
        ' Here's the IMPORTANT thing (ASYNC Command)
		sftp.UploadFileAsync("Local File", "Remote File")

        ' The Loop taking control about the time and adjusting the Speed (here Upload)
		Do While True
            Console.WriteLine("Time: " & System.DateTime.Now)
            Console.WriteLine("Current speed is {0}(KBS)", sftp.KiloBytePerSecond)
            
            Console.WriteLine("Prozent {0}(%)", sftp.PercentComplete)

            TheTime = Now.ToLongTimeString
            If TheTime >= #7:00:00 AM# AndAlso TheTime <= #11:59:59 PM# Then
                TimeStatus = "day"
                If TimeStatusOld <> TimeStatus Then
                    ' Adjusting the speed
					sftp.KiloBytePerSecThrottle = DaySpeed
                    TimeStatusOld = TimeStatus
                End If
            Else
                TimeStatus = "night"
                If TimeStatusOld <> TimeStatus Then
                    ' Adjusting the speed
					sftp.KiloBytePerSecThrottle = NightSpeed
                    TimeStatusOld = TimeStatus
                End If
            End If

            ' If the transfer is done 
			If sftp.IsBusy = False Then
                sftp.Disconnect()
                Console.WriteLine("The highest transfer rate for the current operation is {0}(KBS)", sftp.KiloBytePeak)
                End
            End If
            ' Wait for 10 minutes
			System.Threading.Thread.Sleep(600000)
        Loop

    End Sub

End Module
