Shelless SSH (General questions)
Can this product send an SSH command over to a server without a shell? We have a c# winfom that involks PLINK.EXE to send a command to the server, but it uses a command shell to do so and there is no way to minimize the shell.
Any help would be greatly appreciated.
Re: Shelless SSH
Hi. I may be wrong, but I don't think shell is what the problem is in your case, but terminal window that appears on the screen. Is that correct?
wodSSH by itself doesn't have terminal window, so you can do all the code under the hood. If you want to hide the window itself, you can do it just as any window.
You can specify a Command property to execute a command instad of the shell itself, perhaps this helps. You can also set AllocatePty = false to force hidden mode on the server, if it supports it.
But I'm curious - what are you trying to do? To forward data? Why not using wodSSHTunnel instead of PLINK.EXE?
Hope this helps!
Kreso
Re: Shelless SSH
Hi. I may be wrong, but I don't think shell is what the problem is in your case, but terminal window that appears on the screen. Is that correct?
wodSSH by itself doesn't have terminal window, so you can do all the code under the hood. If you want to hide the window itself, you can do it just as any window.
You can specify a Command property to execute a command instad of the shell itself, perhaps this helps. You can also set AllocatePty = false to force hidden mode on the server, if it supports it.
But I'm curious - what are you trying to do? To forward data? Why not using wodSSHTunnel instead of PLINK.EXE?
Hope this helps!
Kreso
HI Kreso,
We are looking for a C# library that will convert the command below and do it all behind the scenes without a shell. If you have an example of a program we can play with to accomplish this we would happily buy your product.
Here is what we are doing in a nut shell
1) We have 9 Media Star encoder streams in house; each set to a predetermined channel streaming the video using a the RTSP protocol
2) We run a Device Manager job to install VLC and Jack Audio Debian packages on clients
3) When a user connects via RGS to a VM or blade workstation an event is recorded that retains the client IP address from where the connection was initiated from.
4) Each VM or Blade workstation using ThinTV has a WMI script running in memory that reads the Quattro GT7725 IP address and sets and environment variable to the clients IP address “ThinConnectedFrom=172.21.72.57â€.
5) We designed a .net application that uses two components “PLINK.EXE†and a .net application that uses SSH to connect to the thin client, it then runs a command string opening VLC on top of RGS initiating the RTSP protocol to the Media star stream that was selected via a click_event on the .net application.
6) RGS sounds and VLC sounds run on different audio channels
The issue is when getting rid of number 5 putting the command into a win32 appilcation that does not bring up a command shell…. Below is a copy of the command being put through the shell.
string stfamtv0001 = /C + ( PLINK.EXE + + appliance@ ThinConnectedFrom + + -pw appliance + + killall -q vlc; export DISPLAY=:0.0; vlc --volume 512 rtsp://stfamtv0001/streama );
here is the rest of the code….
private void data(string streamPath)
{
System.Diagnostics.Process ps;
ps = new System.Diagnostics.Process();
ps.EnableRaisingEvents = false;
System.Diagnostics.Process.Start( CMD.exe , streamPath);
ps.Close();
}
private void btnFOX_Click(object sender, EventArgs e)
{
data(stfamtv0001);
}
Best regards,
Peter
Re: Shelless SSH
Peter,
I'm not familiar with all the applications you mention in your post, but why not try using wodSSHTunnel component to do what Plink does?
wodSSHTunnel basically does the same thing. It connects to an SSH Server, and creates a tunnel for you. However, everything is done from your application, and no other applications are run (i.e. no command prompt).
Why not try it out? We also have a C# sample included into distribution.
Regards,
Damba
Re: Shelless SSH
Peter,
I'm not familiar with all the applications you mention in your post, but why not try using wodSSHTunnel component to do what Plink does?
wodSSHTunnel basically does the same thing. It connects to an SSH Server, and creates a tunnel for you. However, everything is done from your application, and no other applications are run (i.e. no command prompt).
Why not try it out? We also have a C# sample included into distribution.
Regards,
Damba
Hi Damba,
PLINK is just a simple freeware utility that is command line driven that excepts the aruments state above.
Which example should i use?
Re: Shelless SSH
Peter,
You can download the component from here:
http://www.weonlydo.com/Samples/wodSSHTunnel.exe
Once installed, you can find Samples folder in the install folder. You should have VB6, C#, VC samples, so use whichever suits you.
Regards,
Damba
Re: Shelless SSH
Peter,
You can download the component from here:
http://www.weonlydo.com/Samples/wodSSHTunnel.exe
Once installed, you can find Samples folder in the install folder. You should have VB6, C#, VC samples, so use whichever suits you.
Regards,
Damba
Ok now were would i modify the code in use the command string that i need to?
Re: Shelless SSH
Peter,
I think I misunderstood you previously. You simply need to execute killall -q vlc command on server side?
If so, then I would suggest wodSSH.Net or wodSSH ActiveX. If so, then all the code to accomplish that would be this (using wodSSH.Net):
[code] WeOnlyDo.Client.SSH ssh1 = new WeOnlyDo.Client.SSH();
ssh1.Hostname = your_hostname ;
ssh1.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto;
ssh1.Login = your_login ;
ssh1.Password = your_password ;
ssh1.Blocking = true;
ssh1.Command = killall -q vlc\r\n ;
ssh1.Connect();[/code]
wodSSH.Net is available for download from here: http://www.weonlydo.com/Samples/wodSSH.NET.msi
This is native .Net component.
Regards,
Damba
Re: Shelless SSH
Peter,
I think I misunderstood you previously. You simply need to execute killall -q vlc command on server side?
If so, then I would suggest wodSSH.Net or wodSSH ActiveX. If so, then all the code to accomplish that would be this (using wodSSH.Net):
[code] WeOnlyDo.Client.SSH ssh1 = new WeOnlyDo.Client.SSH();
ssh1.Hostname = your_hostname ;
ssh1.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto;
ssh1.Login = your_login ;
ssh1.Password = your_password ;
ssh1.Blocking = true;
ssh1.Command = killall -q vlc\r\n ;
ssh1.Connect();[/code]wodSSH.Net is available for download from here: http://www.weonlydo.com/Samples/wodSSH.NET.msi
This is native .Net component.
Regards,
Damba
Damba,
Is there a way to have ssh1.Hostname = your_hostname ; read an envirnment variable like ThinConnectedFrom=172.21.72.57 and use the IP address as the hostname?
Re: Shelless SSH
Peter,
From your previous reply I see that you are using ThinConnectedFrom in your C# code. I don't see why you cannot use same thing in wodSSH.NET Hostname Property.
Also you can specify hostname as IP address.
Let us know how it goes.
Drazen
Re: Shelless SSH
Peter,
From your previous reply I see that you are using ThinConnectedFrom in your C# code. I don't see why you cannot use same thing in wodSSH.NET Hostname Property.Also you can specify hostname as IP address.
Let us know how it goes.
Drazen
I already substituted the host name with ThinConnectedFrom and returned the following error on the ssh1.Connect() line
SocketException was unhandled
This would leave me to believe that the ssh1.Hostname is not reading the environment variable correctly, that’s why I posted the question before.
Not sure how else to make this work.
Thoughts?
Re: Shelless SSH
Peter,
Here is example how to read environment variable and environment variable values in C#
[code]System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (System.Collections.DictionaryEntry envVar in envVars)
{
Console.WriteLine(envVar.Key + = + envVar.Value);
}[/code]Can you try that and let us know how it goes?
Drazen
Re: Shelless SSH
Peter,
Here is example how to read environment variable and environment variable values in C#
[code]System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (System.Collections.DictionaryEntry envVar in envVars)
{
Console.WriteLine(envVar.Key + = + envVar.Value);
}[/code]Can you try that and let us know how it goes?
Drazen
Not exactly sure how to get this to work.
I’m not familiar enough with c# coding to pass along the correct variable to make this happen. Here is what I have so far
WeOnlyDo.Client.SSH ssh1 = new WeOnlyDo.Client.SSH();
System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();
private void button1_Click(object sender, EventArgs e)
{
foreach (System.Collections.DictionaryEntry envVar in envVars)
{
Console.WriteLine(envVar.Key + = + envVar.Value);
}
ssh1.Hostname = ThinConnectedFrom ;
ssh1.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto;
ssh1.Login = appliance ;
ssh1.Password = appliance ;
ssh1.Blocking = true;
ssh1.Command = killall -q vlc; export DISPLAY=:0.0; vlc --volume 512 rtsp://stfamtv0001/streama ;
ssh1.Connect();
}
Any help would be greatly apprecieated.
Re: Shelless SSH
Peter,
Are you receiving ThinConnectedFrom variable and value when you list environment variables using my code?
If you do can you show me maybe that line?
Drazen
Re: Shelless SSH
Peter,
Are you receiving ThinConnectedFrom variable and value when you list environment variables using my code?If you do can you show me maybe that line?
Drazen
By using the following code I can see all the variables listed in a command prompt including the ThinConnectedFrom=172.21.72.57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (System.Collections.DictionaryEntry envVar in envVars)
{
Console.WriteLine(envVar.Key + = + envVar.Value);
Console.ReadLine();
}
}
}
}
Re: Shelless SSH
Peter,
Can you please try something like this:[code]
String hostname_value = ;
System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (System.Collections.DictionaryEntry envVar in envVars)
{
if (envVar.Key.ToString() == ThinConnectedFrom )
{
hostname_value = envVar.Value.ToString();
}
}
MessageBox.Show(hostname_value);
WeOnlyDo.Client.SSH ssh1 = new WeOnlyDo.Client.SSH();
ssh1.Hostname = hostname_value;
...[/code]
Drazen
Re: Shelless SSH
Peter,
Can you please try something like this:[code]
String hostname_value = ;System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (System.Collections.DictionaryEntry envVar in envVars)
{
if (envVar.Key.ToString() == ThinConnectedFrom )
{
hostname_value = envVar.Value.ToString();
}
}MessageBox.Show(hostname_value);
WeOnlyDo.Client.SSH ssh1 = new WeOnlyDo.Client.SSH();
ssh1.Hostname = hostname_value;
...[/code]
Drazen
OK got it to work perfectly with this code
private void button1_Click(object sender, EventArgs e)
{
String hostname_value = ;
System.Collections.IDictionary envVars = Environment.GetEnvironmentVariables();
foreach (System.Collections.DictionaryEntry envVar in envVars)
{
if (envVar.Key.ToString() == ThinConnectedFrom )
{
hostname_value = envVar.Value.ToString();
}
}
WeOnlyDo.Client.SSH ssh1 = new WeOnlyDo.Client.SSH();
ssh1.Hostname = hostname_value;
ssh1.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto;
ssh1.Login = appliance ;
ssh1.Password = appliance ;
ssh1.Blocking = true;
ssh1.Command = killall -q vlc; export DISPLAY=:0.0; vlc --volume 512 rtsp://stfamtv0001/streama ;
ssh1.Connect();
}
Is there a way to add logging to it, something that is written to c: emp if the command was not working for some reason?
Re: Shelless SSH
Peter,
Did you receive some response (positive/negative) when you execute command on server?
I'm asking this because you can check server output when command is execute using Receive Method.
Also here is example how to handle connection error with server
[code]
...
ssh1.Command = killall -q vlc; export DISPLAY=:0.0; vlc --volume 512 rtsp://stfamtv0001/streama ;
try
{
ssh1.Connect();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
...
[/code]
Drazen
Re: Shelless SSH
Peter,
Did you receive some response (positive/negative) when you execute command on server?I'm asking this because you can check server output when command is execute using Receive Method.
Also here is example how to handle connection error with server
[code]
...
ssh1.Command = killall -q vlc; export DISPLAY=:0.0; vlc --volume 512 rtsp://stfamtv0001/streama ;
try
{
ssh1.Connect();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
...
[/code]
Drazen
Did not receive a respones either way except the command worked! How would i use the receive method to check the server output?
Re: Shelless SSH
Peter,
You can add in your code Receive Method after Connect Method and check what is received when command is executed.
[code]Console.WriteLine(ssh1.Receive());[/code]
Drazen
Re: Shelless SSH
Peter,
You can add in your code Receive Method after Connect Method and check what is received when command is executed.
[code]Console.WriteLine(ssh1.Receive());[/code]
Drazen
How can i put the results into a txt file?
Re: Shelless SSH
Peter,
Receive method returns a String value. This means that you can simply do something like this:
[code]String result = ssh1.Receive();
System.IO.File.CreateAllText( C:file.txt , result);
[/code]
Can you try that?
Regards,
Damba
Re: Shelless SSH
Peter,
Receive method returns a String value. This means that you can simply do something like this:
[code]String result = ssh1.Receive();
System.IO.File.CreateAllText( C:file.txt , result);
[/code]Can you try that?
Regards,
Damba
Getting the following compile error
Error 1 'System.IO.File' does not contain a definition for 'CreateAllText' C:Documents and SettingsschenkpDesktopWindowsFormsApplication1WindowsFormsApplication1Form1.cs 50 32 WindowsFormsApplication1
Re: Shelless SSH
Peter,
Sorry, use WriteAllText or AppendAllText. Any of them will output the string into a file.
The only difference is that Append will continue writing if the specified file already exists. WriteAllText on the other hand will overwrite the file if it already exists.
Regards,
Damba
Re: Shelless SSH
Peter,
Sorry, use WriteAllText or AppendAllText. Any of them will output the string into a file.
The only difference is that Append will continue writing if the specified file already exists. WriteAllText on the other hand will overwrite the file if it already exists.
Regards,
Damba
OK everything is working perfectly and now Im ready to purchase the product.
Does the one developers license for SSH.NET include unlimited usage of the compiled binary files to be distributed within our organization?
Re: Shelless SSH
Hi Peter,
When you purchase the component, you can distribute it to as many machines and as many projects as you need. We do not have a limit on that.
We only charge our products per developer, which means that each developer working with component should have his own license. I.e: if 5 developers use wodSSH.Net in design mode, you should have 5 licenses.
Regards,
Damba
Re: Shelless SSH
Hi Peter,
When you purchase the component, you can distribute it to as many machines and as many projects as you need. We do not have a limit on that.
We only charge our products per developer, which means that each developer working with component should have his own license. I.e: if 5 developers use wodSSH.Net in design mode, you should have 5 licenses.
Regards,
Damba
Just wanted to thank you and your team for all the help you gave me, your company support is definitly a notch above all the others.
best regards,
Peter