Imports System.IO
Imports AxNetwork
Module TftpGetProgram
Sub Main()
Dim objTftp As New TftpServer()
Console.WriteLine(("ActiveXperts Network Component " + objTftp.Build & ", Module ") + objTftp.[Module])
Console.WriteLine("Expiration Date: " + objTftp.LicenseStatus & vbLf)
' Set Logfile (optional, for debugging purposes)
objTftp.LogFile = Path.GetTempPath() & "Tftp.log"
Console.WriteLine("Log file used: {0}" & vbLf, objTftp.LogFile)
Dim strHost As String = ReadInput("Enter a host name or IP address", "srv202.activexperts-labs.com", True)
Dim strRemoteFile As String = ReadInput("Enter the filename on the remote TFTP host", "/network-component/readme.txt", True)
Dim strFilename As String = ""
If strRemoteFile.Contains("/") Then
strFilename = strRemoteFile.Substring(strRemoteFile.LastIndexOf("/") + 1)
Else
strFilename = strRemoteFile
End If
Dim strLocalFile As String = ReadInput("Enter the filename on the local machine", String.Format("{0}{1}", Path.GetTempPath(), strFilename), True)
objTftp.HostPort = 69
' Default port for TFTP is 69
objTftp.[Get](strHost, strRemoteFile, strLocalFile)
' objTftp.Put("192.168.31.98", "test.txt", "test.txt"); save to remote server
Console.WriteLine("Get, result: " & objTftp.LastError.ToString() & " (" & objTftp.GetErrorDescription(objTftp.LastError) & ")")
Console.WriteLine("Ready.")
System.Threading.Thread.Sleep(3000)
' Sleep for 3 second before exit
End Sub
Private Function ReadInput(ByVal strTitle As String, ByVal strDefaultValue As String, ByVal bAllowEmpty As Boolean) As String
Dim strInput As [String], strReturn As [String] = ""
If strDefaultValue = "" Then
Console.WriteLine(strTitle)
Else
Console.WriteLine(String.Format("{0}, leave blank to use: {1}", strTitle, strDefaultValue))
End If
Do
Console.Write(" > ")
strInput = Console.ReadLine()
If strInput.Length > 0 Then
strReturn = strInput
End If
Loop While strReturn = "" AndAlso Not bAllowEmpty
If strReturn = "" AndAlso strDefaultValue <> "" Then
Return strDefaultValue
End If
Return strReturn
End Function
End Module