Callisto82 / tftp.net

Implements the TFTP (Trivial File Transfer) protocol (client/server) in an easy-to-use C#/.NET library.
Microsoft Public License
80 stars 38 forks source link

It did not support upload files #38

Closed HadesJay closed 1 week ago

HadesJay commented 4 months ago

How to upload files?

StanBJAVS commented 2 months ago

Started with a memory stream....

byte[] bytes = File.ReadAllBytes(openFileDialog.FileName); var memStream = new MemoryStream(bytes);

created a new client with the filename to send to the server.... var client = new TftpClient(ipAddress.Text, 69); var transfer = client.Upload(openFileDialog.FileName);

Set up my events for tracking.... transfer.OnProgress += Transfer_OnProgress; transfer.OnFinished += Transfer_OnFinished; transfer.OnError += Transfer_OnError;

And then use transfer.Start(memStream);

but nothing happens. I sit in a tight Task.Delay().Wait() loop waiting for my file to transfer until I get an Error or Finished message, but the debugger shows NONE of my messages being hit, and the filestream never advances past the first chunk.

Gonna download the repository and see if I can figure out what's going wrong.....

StanBJAVS commented 2 months ago

NOTE: When the initial "write" fails and has to retry, apparently somebody triggers a "negotiation result" message. The NotImplemented Exception stops the transfer for some reason. Implementing the null handler in all cases fixes the crash and allows for error recovery.

So this is the fix to my problem - implement a null handler for the OnOptionAcknowledgement() stub in all cases OR comment out the throw notImplemented in the base interface.

Callisto82 commented 1 week ago

Thanks for debugging this! I removed those NotImplementedExceptions() from StateThatExpectsMessagesFromDefaultEndPoint.