Simple .cshtml example?

Apr 23, 2014 at 6:29 PM
Edited Apr 23, 2014 at 6:30 PM
Major noob here. I'm trying to write a connection string to run really basic commands and get the output. Can someone just show me the simplest way to do this using Razor view engine (.cshtml)? Below is my sad code:
@using Renci.SshNet.Common;
@using Renci.SshNet.Channels;
@using Renci.SshNet.Compression;
@using Renci.SshNet.Sftp;
@using Renci.SshNet.Security;
@using Renci.SshNet.Messages;

@{
    
using (var sshClient = new SshClient("server", "user", "password"))

{

    var terminal = sshClient.RunCommand("ls -l");

    var output = terminal.Result;

}
    
}
This spits out the following error on the line "var terminal = sshClient.RunCommand("ls -l");": "Exception Details: System.ArgumentNullException: Value cannot be null."

Would someone be able to help me?
Apr 23, 2014 at 7:55 PM
I got this to work by doing this:
@using Renci;
@using Renci.SshNet;
@using Renci.SshNet.NetConf;
@using Renci.SshNet.Common;
@using Renci.SshNet.Channels;
@using Renci.SshNet.Compression;
@using Renci.SshNet.Sftp;
@using Renci.SshNet.Security;
@using Renci.SshNet.Messages;

@{
    
var RemoteHost = "server";
var RemoteUserName = "user";
var RemotePassWord = "password";

var connectionInfo = new PasswordConnectionInfo(RemoteHost, RemoteUserName, RemotePassWord); 
var ssh = new SshClient(connectionInfo);
ssh.Connect();
var terminal = ssh.RunCommand("ls -l");

Response.Write(terminal.Result);
}
Marked as answer by seth2958 on 4/23/2014 at 12:55 PM