0

I have been trying to transfer the files using the tftp in C#. I implemented it with the Process class. I have turn on the TFTP client feature in Windows.

This is the command -

C:\Users\Desktop>tftp -i 192.168.43.171 put 
"C:\Users\cc\callisto\SampleTool\src\SampleTool\bin\Debug\DecryptedFiles\dserc.bin"
Transfer successful: 32 bytes in 1 second(s), 32 bytes/s

And the transfer is successful when I execute it manually But When I try it through the code, it says its not recognized -

'tftp' is not recognized as an internal or external command,
 operable program or batch file.

Here is my code

public static void ExecuteCommand(string fileName, string command)
    {
        try
        {
            Process process = new Process();
            process.StartInfo.FileName = fileName;//cmd.exe
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            process.StandardInput.WriteLine(command);//tftp command
            process.StandardInput.Flush();
            process.StandardInput.Close();
            process.WaitForExit();
        }
        catch (Exception ex)
        { }
    }

What is the exact issue I am facing. Can anyone help

Thanks.

  • 1
    Does this answer your question? [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/questions/41454769/what-is-the-reason-for-x-is-not-recognized-as-an-internal-or-external-command) – aschipfl Nov 02 '20 at 12:48
  • Is there are reason you don't run tftp.exe directly `process.StartInfo.FileName = "tftp.exe"`? – Klaus Gütter Nov 02 '20 at 12:57
  • I dont want the end user to install tftp.exe, I tried to do that with command prompt – sreeja sridharan Nov 02 '20 at 13:38
  • I don't understand how calling tftp via cmd.exe would work if tftp is not installed. – Klaus Gütter Nov 02 '20 at 16:21
  • There is never, really NEVER the requirement to run an executable from within a C# coded application by using `cmd.exe`. `cmd.exe` uses the Windows library function [CreateProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) to run any executable which is exactly the same function used by [process class](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process). I think, `tftp.exe` is available only as 64-bit executable in `%SystemRoot%\System32` and your application is a 32-bit application. – Mofi Nov 02 '20 at 18:34

1 Answers1

0

So after so much complication I found this link [https://github.com/Callisto82/tftp.net/blob/master/Tftp.Net.SampleClient/Program.cs]

I was able to transfer the file successfully without any issue. Hopefully this helps