This project has moved and is read-only. For the latest updates, please go here.

Transfer Problem Write

Apr 25, 2014 at 11:56 AM
I'm trying to use this inside a program I am writing.
Using the server sample I have transfer to read without to many issues.
However the sample doesn't appear to show how you would got about writing a file.
static void server_OnWriteRequest(ITftpTransfer transfer, EndPoint client)
            Console.WriteLine("[" + transfer.Filename + "] Write request from "+ client + " for " + transfer.Filename);
            Console.WriteLine("[" + transfer.Filename + "] Denying request.");
This just returns Error#4 Illegal Operation.

Does anyone know how I should go about writing to the server?
Jun 15, 2014 at 10:59 AM
Hi PelPet,

sorry for responding so late. It seems that I don't even get notifications about new threads in the Forum :(
Writing a file works just like reading one. Basically, you open a stream that should receive the file (for example a MemoryStream or a FileStream) and then call Transfer.Start with that stream. Also, you may want to bind transfer.OnError and transfer.OnFinished to learn when the upload finished..

For example, the following code receives a file to a local Directory:
    //Bind events so that you receive progress, errors, etc.
    transfer.OnProgress += new TftpProgressHandler(transfer_OnProgress);
    transfer.OnError += new TftpErrorHandler(transfer_OnError);
    transfer.OnFinished += new TftpEventHandler(transfer_OnFinished);
    //Start the actual transfer
    String targetFile = Path.Combine(@"C:\TftpRoot", transfer.Filename);
    transfer.Start(new FileStream(targetFile, FileMode.Create));