|
From: <Nic...@ne...> - 2009-11-24 14:39:44
|
In reply to
[Sharpssh-users] Help needed for interactive command
from
Thorsten Harms <thorsten.harms@ar...>
Hi Thorsten,
did you found any snippet of a manual? Me not and therefore it is really time consuming in finding out how SharpSSH works.
By trying and from the examples I successfully found out how to:
- scp
- connect via ssh
- execute a command via ssh (but different object than the one before)
Here are my snippets:
<SCP>
// Initialize Object
Tamir.SharpSsh.Scp sshScp = new Tamir.SharpSsh.Scp(sHost, sUser, sPw);
// Try to connect
sshScp.Connect();
// Check if the connection succeeded
if (sshScp.Connected)
{
logBaseLogger.writeLog("Successfully connected to '" + sHost + "'", Logger.LogId.Step8);
// Transmit ipexp script file
sshScp.Put("my\secret\path", dicAppSettings["sScriptPath"].ToString());
sshScp.Close();
logBaseLogger.writeLog("Connection closed.");
}
else
{
logBaseLogger.logLevel = Logger.LogLevel.Warning;
logBaseLogger.writeLog("SCP connection failed!" + nl + "Could not connect to host: " + sHost, Logger.LogId.Step8);
}
</SCP>
<SHELL>
Tamir.SharpSsh.SshShell sshShell = new Tamir.SharpSsh.SshShell(sHost, sUser, sPw);
sshShell.Connect();
<same if(connected) as above>
// Get shell stream
//StreamReader srShellReader = new StreamReader(sshShell.GetStream());
// Output of stream content
//while (srShellReader.Peek() != -1)
//{
// logBaseLogger.writeLog("SSH$ " + srShellReader.ReadLine());
//}
</SHELL>
<EXECUTE>
Tamir.SharpSsh.SshExec sshCL = new Tamir.SharpSsh.SshExec(sHost, sUser, sPw);
// Try to connect
sshCL.Connect();
// Check if the connection succeeded
if (sshCL.Connected)
{
logBaseLogger.writeLog("Successfully connected to '" + sHost + "'", Logger.LogId.Step8);
// Send command
logBaseLogger.writeLog(sshCL.RunCommand("dir"));
// Finish
sshCL.Close();
logBaseLogger.writeLog("Connection closed.");
}
</EXECUTE>
Just forget my generic logging object.
Maybe it helps.
Any hints, tips or general comments on using SharpSSH appreciated - as I said above, its really time consuming to find out how everything works.
Regards,
Nicolas
Mit freundlichen Grüßen
Nicolas Krzywinski
Fachinformatiker/Systemintegration
Consultant Professional Services NXR/SW/OPS
|