A Little Help With Connection Settings

Jan 9, 2013 at 7:31 PM

Just found your project.  Looks pretty good.  Having a small issue getting going.

Used the example code as a base such that I have this:

using (var client = new SshClient("<host>", "<user>", "<pass>")) {
   try {
      client.Connect();
      var cmd = client.CreateCommand("ll ~");
      cmd.Execute();
      client.Disconnect();
   }
   catch( Exception ex ) {
System.Diagnostics.Debug.WriteLine(ex.StackTrace); 
   }
   finally {
      if( client.IsConnected ) { client.Disconnect(); }
   }
}

Running this code yeilds: "bash: ll: command not found"

If I change the command from "ll ~" to "ls ~", lo and behold it works.

It appears that the connection isn't seen by the server as an interactive terminal session so that all the various bash profile pieces aren't being executed.

 

Am I missing something about how to configure SSH.NET so the server sees this as just another ssh session?

Thanks,

Michael

Coordinator
Jan 9, 2013 at 8:30 PM

Hi,

 

Unfortunately I cannot provide much help with that since the issue you described is server specific.

When command is executed it runs in its own environment, which probably set up differently from shell.

I can't be much help there since I am not a UNIX person so wouldn't know how to configure it.

 

Thanks,

Oleg

Jan 29, 2013 at 5:19 PM

Sorry, I was off on another project for a bit.  Trying a different tack now.  Let me see if this better illustrates what I'm trying to accomplish and if you can offer any further assistance from this. 

 

SshShell shell = new SshShell("<host>", "<user>", "<pass>");
shell.RemoveTerminalEmulationCharacters = true;

//This statement must be prior to connecting
//shell.RedirectToConsole();

Console.Write("Connecting...");
shell.Connect();
Console.WriteLine("OK");

MemoryStream stream = new MemoryStream();
shell.SetStream(stream);

StreamWriter command = new StreamWriter(stream);
command.WriteLine("ll");
command.Flush();
//stream.Position=0;

StreamReader response = new StreamReader(stream);
Console.WriteLine(response.ReadToEnd());
//stream.Position = 0;

command.WriteLine("exit");
command.Flush();
//stream.Position = 0;

response = null;
command = null;
stream.Close();
stream.Dispose();
stream = null;

shell.SetStream(null);

//while(shell.ShellOpened)
//{
//	System.Threading.Thread.Sleep(500);
//}

 
Console.Write("Disconnecting...");
shell.Close();
Console.WriteLine("OK");

 

Thanks,

Michael

Coordinator
Feb 3, 2013 at 12:06 AM
Hey,
Sorry for late response but I dont think you using this library based on your code example.
Some methods and properties dont exists.

And again, I am not so familiar with unix to know how to make "ll" command work :(:(

Thanks,
Oleg
Feb 3, 2013 at 5:47 AM
<div>You're right, sorry. I'm trying things from multiple sources and got that one crossed up.<br> <br> Sent from my iPad</div> <div><br> On Feb 2, 2013, at 7:07 PM, &quot;olegkap&quot; &lt;<a href="mailto:notifications@codeplex.com">notifications@codeplex.com</a>&gt; wrote:<br> <br> </div> <blockquote type="cite"> <div> <p>From: olegkap</p> <div id="ThreadNotificationPostBody">Hey, Sorry for late response but I dont think you using this library based on your code example. Some methods and properties dont exists. And again, I am not so familiar with unix to know how to make &quot;ll&quot; command work :(:( Thanks, Oleg</div> </div> </blockquote>