Search code examples
c#shellwinscpwinscp-net

How to run a shell script [.sh] from WinSCP process in C# .NET


I have done the following steps successfully:

  1. I have created an WinSCP [Process] in C# .NET
  2. Created a Session of a user on LINUX-server [Using SFTP Protocol]
  3. Downloaded the files using GetFiles(........);

The thing I want to add to my App is that:

  • Give that process a command to run a shell-script [already uploaded on the server]
  • I tried this session.ExecuteCommand("sh /fol1/fol1_1/abc.sh");
    but giving no results/impacts

Solution

  • To execute a shell command on the server using WinSCP .NET assembly, use the Session.ExecuteCommand:

    session.ExecuteCommand("sh abc.sh");
    

    This will work with the SCP and the SFTP (with limitations) protocols only.
    See https://winscp.net/eng/docs/library_session_executecommand#remarks