Putty.

mercoledì 27 giugno 2012 - 16.16
Tag Elenco Tags  VB.NET  |  .NET 4.0

iif Profilo | Expert

Ciao, vorrei creare un'app con la quale inviare comandi a putty.
Dove posso trovare un tutorial?
Grazie.

StefanoRicci Profilo | Junior Member

http://stackoverflow.com/questions/603187/how-to-send-commands-to-putty
--------------------------------------

IDE: Visual Studio 2008 Professional Edition
IDE: Visual Studio 2010 Professional Edition

Vinsent Profilo | Senior Member

Premetto che non conoscevo putty, ho letto adesso su wikipedia...
Tempo fa, per imparare ad usare processi e delegati ho creato un programma che "voleva" essere un' interfaccia grafica a cmd.exe...
Il sunto, con il codice alla fine, è una Form con due TextBox, un Button, un BackgroundWorker:

Tbox_input
Tbox_output
Button_invio
BackgroundWorker1

Tbox_input è la TextBox dove scrivere il comando DOS, Button_invio è il Button...per eseguirlo.
Tbox_output è una TextBox Multiline in cui viene scritto l' output di CMD.
CMD.EXE viene eseguito dal BackgroundWorker per non bloccare la Form durante l' esecuzione dei comandi, dove leggi "delegato" serve per non avere problemi di "cross thread exception".
Quindi, scrivi il comando su Tbox_input (ad esempio: ping google.it) e clicca sul Button_invio, sulla Tbox_output verranno scritte le stesse informazioni che leggeresti su CMD.
Vedi tu se riesci a fare lo stesso con putty...
Il codice:
Imports System.Threading Imports System.IO Public Class Form1 Dim WithEvents pr As New Process() Delegate Sub pr_delegato(ByVal riga As String) Dim myStreamWriter As StreamWriter Private Sub Form1_Load() Handles MyBase.Load BackgroundWorker1.RunWorkerAsync() End Sub Private Sub BackgroundWorker1_DoWork() _ Handles BackgroundWorker1.DoWork Dim args As New ProcessStartInfo("cmd.exe") With args .RedirectStandardOutput = True .RedirectStandardInput = True .UseShellExecute = False .CreateNoWindow = True End With pr = Process.Start(args) myStreamWriter = pr.StandardInput pr.BeginOutputReadLine() myStreamWriter.WriteLine("cd c:\") End Sub Private Sub scrivi(ByVal riga As String) Tbox_output.AppendText(riga) End Sub Public Sub scrivi_delegato(ByVal riga As String) Dim a As New pr_delegato(AddressOf scrivi) Invoke(a, New Object() {riga & vbCrLf}) End Sub Private Sub pr_outline(sendingProcess As Object, _ outLine As DataReceivedEventArgs) _ Handles pr.OutputDataReceived If Not String.IsNullOrEmpty(outLine.Data) Then scrivi_delegato(outLine.Data) End If End Sub Private Sub Button_invio_Click() Handles Button_invio.Click myStreamWriter.WriteLine(Tbox_input.Text) End Sub End Class

iif Profilo | Expert

Grazie per il suggerimento.
Dovrei anche immettere le credenziali di accesso e lanciare una serie di comandi.

Grazie.

Vinsent Profilo | Senior Member

Nel link postato da StefanoRicci trovi quello che ti serve...vedi il post dell' utente "Powerlord" dove dice che è possibile usare Plink(Plink (PuTTY Link) is a command-line connection) da CMD, nel messaggio c' è anche il link(Chapter 7) alla documentazione:
http://tartarus.org/~simon/putty-snapshots/htmldoc/Chapter7.html
Tra il codice che ho postato e il "Chapter 7" penso che le basi ci siano tutte...in pratica devi vedertela tu!
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5