public LiveHostClient(string sHostName, string sRemoteSupportUser, string sRemoteSupportPassphrase) { RemoteSupportPassphrase oReportSupportPassphrase = new RemoteSupportPassphrase(); String sUserPassword = oReportSupportPassphrase.Decode(sRemoteSupportPassphrase); Renci.SshNet.AuthenticationMethod authMethod = new Renci.SshNet.PasswordAuthenticationMethod(sRemoteSupportUser, sUserPassword); scpConnInfo = new Renci.SshNet.ConnectionInfo(sHostName, sRemoteSupportUser, new[] { authMethod }); scpClient = new Renci.SshNet.ScpClient(scpConnInfo); MemoryStream xmlStream = new MemoryStream(); scpClient.Connect(); System.Threading.Thread.Sleep(3000); try { scpClient.Download(@"/usr/local/platform/conf/platformConfig.xml", xmlStream); } catch (Exception ex) { string bob = ex.Message; } scpClient.Disconnect(); byte[] xmlDataBytes = new byte[xmlStream.Length]; xmlStream.Seek(0, SeekOrigin.Begin); xmlStream.Read(xmlDataBytes, 0, (int)xmlStream.Length); Console.Write("{0}\n", Functions.encoding.GetString(xmlDataBytes)); }
public static Renci.SshNet.SshClient GetSSHConnection(SSHSecurityOption sshSecurityOption, string machineName, int sshPort, string userName, string password, string privateKeyFile, string passCodeOrPhrase) { Renci.SshNet.SshClient sshClient; if (sshSecurityOption == SSHSecurityOption.Password) { byte[] b = System.Text.UTF8Encoding.UTF8.GetBytes(password.ToCharArray()); Renci.SshNet.AuthenticationMethod am = new Renci.SshNet.PasswordAuthenticationMethod(userName, b); Renci.SshNet.ConnectionInfo ci = new Renci.SshNet.ConnectionInfo(machineName, sshPort, userName, am); sshClient = new Renci.SshNet.SshClient(ci); } else if (sshSecurityOption == SSHSecurityOption.PrivateKey) { Renci.SshNet.PrivateKeyFile[] pkf = new Renci.SshNet.PrivateKeyFile[1]; pkf[0] = new Renci.SshNet.PrivateKeyFile(privateKeyFile, passCodeOrPhrase); Renci.SshNet.PrivateKeyAuthenticationMethod pm = new Renci.SshNet.PrivateKeyAuthenticationMethod(userName, pkf); Renci.SshNet.ConnectionInfo ci = new Renci.SshNet.ConnectionInfo(machineName, sshPort, userName, pm); sshClient = new Renci.SshNet.SshClient(ci); } else { Renci.SshNet.KeyboardInteractiveAuthenticationMethod kauth = new Renci.SshNet.KeyboardInteractiveAuthenticationMethod(userName); Renci.SshNet.PasswordAuthenticationMethod pauth = new Renci.SshNet.PasswordAuthenticationMethod(userName, password); keyBoardPassword = password; kauth.AuthenticationPrompt += new EventHandler <Renci.SshNet.Common.AuthenticationPromptEventArgs>(HandleKeyEvent); sshClient = new Renci.SshNet.SshClient(new Renci.SshNet.ConnectionInfo(machineName, sshPort, userName, pauth, kauth)); } if (machineName.Trim().Length > 0) { sshClient.Connect(); } return(sshClient); }
public Client(string sHostName, string sRemoteSupportUser, string sRemoteSupportPassphrase) { RemoteSupportPassphrase oReportSupportPassphrase = new RemoteSupportPassphrase(); String sUserPassword = oReportSupportPassphrase.Decode(sRemoteSupportPassphrase); Renci.SshNet.AuthenticationMethod authMethod = new Renci.SshNet.PasswordAuthenticationMethod(sRemoteSupportUser, sUserPassword); scpConnInfo = new Renci.SshNet.ConnectionInfo(sHostName, sRemoteSupportUser, new[] { authMethod }); scpClient = new Renci.SshNet.ScpClient(scpConnInfo); }