public void SendFirmware(string path) { if (File.Exists(path)) { using (m_Server = new TftpServer()) { m_Server.OnReadRequest += OnReadRequest; using (m_Client = new UdpClient(new IPEndPoint(IPAddress.Any, LocalPort))) { m_Client.Client.ReceiveTimeout = 2000; m_Path = path; m_TransferHasError = false; m_TransferHasFinished = false; m_Server.Start(); if (!RequestDeviceName() || !ConfigureDeviceForDHCP() || !RequestDeviceIP() || !InitiateDeviceUpdate(path)) { return; } while (!m_TransferHasFinished) { if (m_TransferHasError) { return; } Thread.Sleep(1000); } } } } }
public main() { InitializeComponent(); this.Load += main_Load; server = new TftpServer(); server.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest); server.OnWriteRequest += new TftpServerEventHandler(server_OnWriteRequest); }
protected override void Dispose(bool disposing) { if (server != null) // since Dispose can be called multiple times { server.Dispose(); server = null; } }
public PixeyTftpServer( IPixeyTftpTransferFactory transferFactory, ILogger <PixeyTftpServer> logger) { _transferFactory = transferFactory; _logger = logger; _tftpServer = new TftpServer(); _tftpServer.OnWriteRequest += HandleWriteRequest; _tftpServer.OnReadRequest += HandleReadRequest; _tftpServer.OnError += HandleError; }
public TFTPServer(IPAddress localAddress, int port, string rootDirectory) { server = new TftpServer(localAddress, port); ServerDirectory = rootDirectory; server.OnReadRequest += Server_OnReadRequest; server.OnWriteRequest += Server_OnWriteRequest; server.Start(); Trace.WriteLine($"Start TFTPD on {localAddress.ToString()}:{port.ToString()}"); Trace.WriteLine($"TFTP root dir: {rootDirectory}"); Trace.Flush(); }
public void run(string dir, ServerForm _form) { form = _form; ServerDirectory = dir; Debug.Write("Server dir " + ServerDirectory); tftpServer = new TftpServer(); { tftpServer.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest); tftpServer.OnWriteRequest += new TftpServerEventHandler(server_OnWriteRequest); tftpServer.Start(); form.Log.Invoke($"Server started!"); } }
public Server() { if (s_instance != null) { throw new Exception("Only a single instance of TFTP Server can be instantiated at a time"); } s_instance = this; m_server = new TftpServer(); m_server.OnReadRequest += server_OnReadRequest; m_server.OnWriteRequest += server_OnWriteRequest; m_server.Start(); }
public static void ResimveSeslerGonder() { ServerDirectory = Environment.CurrentDirectory; Debug.WriteLine("Running TFTP server for directory: " + ServerDirectory); using (var server = new TftpServer()) { server.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest); server.OnWriteRequest += new TftpServerEventHandler(server_OnWriteRequest); server.Start(); } }
public void startTftpServer() { ServerDirectory = Environment.CurrentDirectory + "\\ipxe"; using (var server = new TftpServer()) { server.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest); server.OnWriteRequest += new TftpServerEventHandler(server_OnWriteRequest); server.Start(); Console.WriteLine("Running TFTP server for directory: " + ServerDirectory); while (true) { Thread.Sleep(10000); } } }
static void Main(string[] args) { ServerDirectory = Environment.CurrentDirectory; Console.WriteLine("Running TFTP server for directory: " + ServerDirectory); Console.WriteLine(); Console.WriteLine("Press any key to close the server."); using (var server = new TftpServer()) { server.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest); server.OnWriteRequest += new TftpServerEventHandler(server_OnWriteRequest); server.Start(); Console.Read(); } }
static void Main(string[] args) { ServerDirectory = System.IO.Path.GetTempPath() + "configFiles"; Console.WriteLine("Running TFTP server for directory: " + ServerDirectory); Console.WriteLine(); //Console.WriteLine("Press any key to close the server."); using (var server = new TftpServer()) { server.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest); server.OnWriteRequest += new TftpServerEventHandler(server_OnWriteRequest); server.Start(); while (Console.ReadKey(true).Key != ConsoleKey.Escape) { } } }
public void ClientsReadsFromServer() { using (TftpServer server = new TftpServer(new IPEndPoint(IPAddress.Loopback, 69))) { server.OnReadRequest += new TftpServerEventHandler(server_OnReadRequest); server.Start(); TftpClient client = new TftpClient(new IPEndPoint(IPAddress.Loopback, 69)); using (ITftpTransfer transfer = client.Download("Demo File")) { MemoryStream ms = new MemoryStream(); transfer.OnFinished += new TftpEventHandler(transfer_OnFinished); transfer.Start(ms); Thread.Sleep(500); Assert.IsTrue(TransferHasFinished); } } }
public void WriteThenRead() { int fileSize = 8192; using (TestFile inputFile = new TestFile(fileSize)) using (TestFile outputFile = new TestFile()) { TftpClient tftpClient = new TftpClient(); TftpServer tftpServer = new TftpServer(); IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 69); string remoteName = "file0"; CancellationTokenSource cts = new CancellationTokenSource(); tftpClient.Write(remoteEP, remoteName, inputFile.Path, cts.Token); tftpClient.Read(remoteEP, remoteName, outputFile.Path, cts.Token); byte[] inputBytes = File.ReadAllBytes(inputFile.Path); byte[] outputBytes = File.ReadAllBytes(outputFile.Path); Debug.Assert(inputBytes.Length == outputBytes.Length); for (int i = 0; i < inputBytes.Length; ++i) { Debug.Assert(inputBytes[i] == outputBytes[i]); } tftpServer.Stop(); } }