0

Below is the code where I'm trying to run one command with argument. (Call Tectia SFTP client profile & upload file)

        Process cmd = new Process();
        cmd.StartInfo.FileName = "cmd.exe";
        cmd.StartInfo.Arguments = $"/c sftpg3 {profile}";
        cmd.StartInfo.RedirectStandardInput = true;
        cmd.StartInfo.RedirectStandardOutput = true;
        cmd.StartInfo.CreateNoWindow = true;
        cmd.StartInfo.UseShellExecute = false;
        cmd.Start();

        using (StreamWriter sw = cmd.StandardInput){
                    if (sw.BaseStream.CanWrite)
                        sw.WriteLine($"/c sput {filename} {output}");
         }

After the process started, it logins into the into the SFTP and stucked. It won't input the next command as it deemed as another program.

Would like to ask how does it execute the next command after login? I tried Calling CMD with && concatenating and it won't works too. We can only use SFTP via command line as client requested.

10
  • Don't you need to redirect the standard input like so cmd.StartInfo.RedirectStandardInput = true; in order to use it ? Commented Aug 7, 2018 at 17:18
  • It was removed temporary when I was testing with other methods. Added it back. Still won't work even with those options available. Commented Aug 7, 2018 at 17:22
  • does that application have the ability to pass in a file parameter as a script so you don't have to try to redirect standard input? Commented Aug 7, 2018 at 17:29
  • Unfortunately no. We have to login first before upload the file. Commented Aug 7, 2018 at 17:32
  • 1
    MSDN sample works i just tried it. Commented Aug 7, 2018 at 17:40

1 Answer 1

2
  • Launch sftpg3 with the -B - option to read from standard input.

  • Launch sftpg3 with the -B <filename> option to read from a batch file of commands.

More details of command line arguments is available in the documentation.

Also, I don't think you want to write /c the second time around. /c is just something passed to cmd.exe. On that note, why are you calling cmd.exe instead of the binary directly?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.