Solved

Code example for plink.exe redirect of results

Posted on 2011-09-29
5
1,874 Views
Last Modified: 2012-05-12
I am hoping somebody could provide a code example of how plink.exe can be used to log into a linux server, run a few commands and direct all of the ouput to a textbox within VB.net 2010.

I know the command line to get the connection....
       Dim Unix_User_Name As String = "XXX"
        Dim Unix_User_Password As String = "XXX"
        Dim NDS_Start_SIT_Putty_Command_Value As String = "C:\plink.exe " + Unix_User_Name + "@spongeshrimp.grhq.XXX.com -pw " + Unix_User_Password

Open in new window


But then what I want to do is a....
ls -la

Open in new window


And then capture all the reults of that command in a textbox.  I know this is done through streamreading however I am not that up on how this is acomplished.  I just need a code example.

Thank you.
0
Comment
Question by:larrylroberts
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Russell_Venable earned 500 total points
ID: 36894644
Hi Larryltoberts,

First you are going to need to register the directory that has plink in it by setting it's user environment for system and user (depends on your system). You can set the path by using the cmd prompt and setting the path using the "PATH" command or going to my computer and right click and select properties, goto "advanced" tab and look towards the bottom
for Environment variables click this, next go to system variables and open up PATH and add your directory to plink after the last " ; ". Now that this is done you will need to reboot for this to take effect.

This article here is a perfect example of command prompt redirection using VB.NET. http://www.vbforums.com/showthread.php?t=381405.

After you have d/l and compiled you can use plink like so.
create a text file named commands.txt and place the commands you wish to run and save the text file now open the VB.NET project compile and run the binary and run that command it should give you exactly what your asking for.
Plink -ssh -l <username> -pw <yourpass> -t -m commands.txt -s
0
 
LVL 15

Expert Comment

by:Russell_Venable
ID: 37184032
Well I gave the answer. I answered what the OP asked for. Just didn't get a response back. This will do exactly as wanted.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 37260985
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question