I'm using SshClient from Renci.SshNet and i have noticed that all the commands are not effective on the remote server.
For example, that one works fine :
mySSH.RunCommand( "touch test");
will create a file on the remote server.
but this one won't do anything :
mySSH.RunCommand( "nohup dnx web &");
I searched all over the internet and i'm so disapointed cause nobody talk about that.
Mostly, all commands that are simple like create a file or a folder, but strong commands like executing a script or starting my application (the most important) just simply don't want to do anything.
Thank you in advance.
Can you run this command when you log in over ssh as the same user Ssh.Net is using?
Related
I have a directory full of DICOM on a linux file server. I have the directory mapped as a network drive and have created a c# console application for modifying the DICOM tags, modifying DICOM tags is something I must do before I can import to our database.
When I am in the server I can run the following to import everything from this directory to my database:
for x in `ls -d1 *`;
do
dcmbase_import -U p_mfdid1 -n -l info -i "$x:spiromics:file:H:SPIROMICS";
done
I would like to know if there is a way that I can run the above code from within the c# application. For instance, is there a way to access the linux file server and execute a shell script?
Currently I have to run my c# application to change heads and then manual access the server and run the shell script. I would love to have this all encompassed in one application so that I could run it at the end of the day and have it processing and importing over night.
You can't run the shell script over the network share as that would run it on your local machine and you need to run it on the Linux machine.
The common method for executing code remotely is by running it with SSH or invoking with RPC. I would avoid RPC if possible because even though it's more powerful it also needs more complicated setup.
From Karl-Johan Sjögren's answer on this question, C# send a simple SSH command, I was able to find a git project for SSH calls in .NET as well as a small stub that could get you started. You would change hostnameOrIp to your Linux server, and change the command to be run to your script.
SSH.NET
using (var client = new SshClient("hostnameOrIp", "username", "password"))
{
client.Connect();
client.RunCommand("etc/init.d/networking restart");
client.Disconnect();
}
For school we need to build a webinterface which interacts with the program DaHaus (a sort of autonomation program).
As of now I first made contact simply with putty and that worked.
However I found out that I couldn't make that connection automated since putty had an UI.
Then I tried plink which could connect to the program but once it did I couldn't type a single thing.
How to connect: telnet with port number 11000 and localhost or 127.0.0.1
I am wondering if its possible to make plink do the commands in a way that works or how to do it with putty without the shell since it needs to be automated.
Also the code we need to make it in is c# with visual studio in asp.net
https://www.codeproject.com/Articles/19071/Quick-tool-A-minimalistic-Telnet-library
using this library you can set up a telnet connection with whatever program you want. For using it inside a project simply copy the telnetinferface.cs file to the correct folder inside your project.
within your code simply state using TelnetInterface;
I am making an simple application on PC by C# to send command to jailbroken iphone (exp: open app, get list application installed on iphone..e.t.c..) but I do not know how to send to iphone, searching google but can not find a thing to do this. Anyone know how to send command to iphone please point me out or some documents to learn about this.
Thank you.
in my opinion the best way to go is using SSH, here's the steps
On the Jailbroken device (Skip this steps if you already have an ssh server installed and running)
Download the SSH server from Cydia
Take note of your device's IP address
Default username: root and password: alpine Remember to change that!, also i would recommend creating another user for your app
In your application
Download and install the SSH.NET library from NuGET here
Implement your appropriate methods to connect,disconnect and send commands, se those examples:
using (var client = new SshClient("phoneIp", "phoneUsername", "phonePassword")) {
client.Connect();
//Open the Facebook app and show your profile
client.RunCommand("open fb://profile");
//Alternative method using `uiopen`
client.RunCommand("uiopen fb://profile");
//Read device network info (install network-cmds first)
Console.WriteLine(client.RunCommand("ifconfig"));
//List all apps installed via Cydia
Console.WriteLine(client.RunCommand("dpkg –list"));
//List all apps that are installed from iTunes/Appstore
Console.WriteLine(client.RunCommand("cat /private/var/mobile/Library/Caches/com.apple.mobile.installation.plist"));
client.Disconnect();
}
I haven't tested this code of course, and I have no Jailbroken iOS device, but this should put you on the right path at least!
First you have to create a daemon on your jailbroken iDevice. It will contain a TCP server, which accepts connections from your PC and translates them into your commands. After that commands will be executed by your daemon and you have to write code to process each type of command.
Another one easy solution would be to use Cycript in conjunction with SSH.
If Cycript is installed on the jailbroken phone and a SSH server is running, you could write some scripts and upload it to the phone.
By running them, it would output relevant informations to the standard output.
You would still have to do some very basic reversing stuff to know what you want to to display (i.e. asking the right SpringBoard controller to have the desired information)
I am planning to do an App either in c++/C# (through Visual Studio) in Windows 7.
OK what this app does is it will accept input through studio elements like text box or buttons ..then it should create an command based on input and run these command on the Linux server.
E.g : One simple example is to restart a certain process on a Linux machine
Now to proceed to my problem:
How do I connect my App to Linux machine?
I don't want to install any third party application as i am not allowed to do so.
If possible please list me the different ways i can do this
Well, you can do this. I am already familiar with this scenario. I have several application setup working this way. The only option that will allow you to do this without any 3rd party application is using SSH protocol.
The SSH protocol is the well known and most power full tool of linux sysadmins. You can execute any command over it on a linux box from any part of the world or any piece of shit which can run an SSH client. Ask me on comment if you need more info on this.
EDIT
One example, if you want to restart certain process.. You can pass the command over SSH as below.
ssh user#server_ip '/etc/init.d/httpd restart"
The above will restart the HTTPD(Apache) service.
Some libraries you can use in .NET
http://www.codeproject.com/Articles/11966/sharpSsh-A-Secure-Shell-SSH-library-for-NET
https://sshnet.codeplex.com/
I have not used above libraries in .Net, Instead I have done several things using linux box with python and bash.
if I understand correctly, to solve this you can implemente WebService.
But when you said :
I dont want to install any third party application as i am not allowed
to do so
I'm afraid you can not setup WebService on Linux server ?
Other possibility, use SSH if already install on linux server (some chance that is) and you probably could find a .Net lib to make SSH
This link will help .Net class to execute remotely on Linux over SSH?
I am wondering if it is possible to connect to a git server that is hosted on another server (running Linux) through a C# ASP.NET application. I am only looking for reading capabilities to be able to display information of that git repository in the ASP.NET application.
SharpSSH is really easy to use and i've never had any problems with it, it will let you connect via SSH and run commands, or use SCP to copy files from the server.
I would simply stream the output that a local msysgit command would return.