public async Task <string> GetAsync(string fuwudizhi, string zhanghao, string mima, string cmd) { SSHHelper ssh = new SSHHelper(fuwudizhi, zhanghao, mima); string test = "ok";//ssh.RunCommand(cmd); return(string.Format("{0}:{1}>{2}....{3}", fuwudizhi, zhanghao, mima, test)); }
public void Connect(string ip, string username, string password) { SSH = new SSHHelper(ip, username, password); if (SSH.SSHClient == null) { throw new Exception(string.Format("Machine {0} cannot be connected", Name)); } }
private void InitializeConnections() { List <IConnectionViewModel> connections = new List <IConnectionViewModel>(); connections.Add(new LocalConnectionViewModel()); connections.AddRange(SSHHelper.GetAvailableSSHConnectionInfos().Select(item => new SSHConnectionViewModel(item))); SupportedConnections = new ObservableCollection <IConnectionViewModel>(connections); OnPropertyChanged(nameof(SupportedConnections)); }
/// <summary> /// 处理消息命令cmd表示消息命令,msg表示消息内容 /// </summary> /// <param name="jmsg"></param> /// <returns></returns> public static async Task ExcMsgCmd(JToken jmsg, string userid) { if (jmsg == null || jmsg["cmd"] == null) { await SocketHelper.SendMessageAsync(userid, "错误消息"); } try { switch (jmsg["cmd"].ToString()) { case "connet": { _userSSH.Remove(userid); SSHHelper ssh = new SSHHelper(jmsg["dizhi"].ToString(), jmsg["zhanghu"].ToString(), jmsg["mima"].ToString()); if (!ssh.IsConnet) { ssh = null; SocketHelper.SendMessageAsync(userid, "connet faild"); return; } await SocketHelper.SendMessageAsync(userid, "conneted"); _userSSH.Add(userid, ssh); ssh.DataReceived += (sh, data) => { if (data.msgType == SshMessageEnum.zifuchuan) { SocketHelper.SendMessageAsync(userid, data.msgContent); } }; ssh.RunCommand("cd /"); break; }; case "excmd": { SSHHelper ssh = null; if (!_userSSH.TryGetValue(userid, out ssh)) { await SocketHelper.SendMessageAsync(userid, "执行失败"); } ssh.RunCommand(jmsg["msg"].ToString()); break; }; default: await SocketHelper.SendMessageAsync(userid, "错误消息"); break; } } catch (Exception ex) { Console.WriteLine(string.Format("消息处理错误:{0}__{1}", jmsg.ToString(), ex.Message)); } }
public static SSHConnection GetSSHConnection(string name) { ConnectionInfoStore store = new ConnectionInfoStore(); ConnectionInfo connectionInfo = null; StoredConnectionInfo storedConnectionInfo = store.Connections.FirstOrDefault(connection => { return(name.Equals(SSHPortSupplier.GetFormattedSSHConnectionName((ConnectionInfo)connection), StringComparison.OrdinalIgnoreCase)); }); if (storedConnectionInfo != null) { connectionInfo = (ConnectionInfo)storedConnectionInfo; } if (connectionInfo == null) { IVsConnectionManager connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager)); IConnectionManagerResult result; if (string.IsNullOrWhiteSpace(name)) { result = connectionManager.ShowDialog(); } else { string userName; string hostName; int atSignIndex = name.IndexOf('@'); if (atSignIndex > 0) { userName = name.Substring(0, atSignIndex); int hostNameStartPos = atSignIndex + 1; hostName = hostNameStartPos < name.Length ? name.Substring(hostNameStartPos) : StringResources.HostName_PlaceHolder; } else { userName = string.Format(CultureInfo.CurrentCulture, StringResources.UserName_PlaceHolder); hostName = name; } result = connectionManager.ShowDialog(new PasswordConnectionInfo(hostName, userName, new System.Security.SecureString())); } if ((result.DialogResult & ConnectionManagerDialogResult.Succeeded) == ConnectionManagerDialogResult.Succeeded) { // Retrieve the newly added connection store.Load(); connectionInfo = store.Connections.First(info => info.Id == result.StoredConnectionId); } } return(SSHHelper.CreateSSHConnectionFromConnectionInfo(connectionInfo)); }
protected IConnection GetConnection() { if (this.sshConnection == null) { if (this.connectionInfo != null) { this.sshConnection = SSHHelper.CreateSSHConnectionFromConnectionInfo(connectionInfo); } } return(this.sshConnection); }
private void InitializeConnections() { List <IConnectionViewModel> connections = new List <IConnectionViewModel>(); connections.Add(new LocalConnectionViewModel()); if (SupportSSHConnections) // we currently only support SSH for Linux Containers { connections.AddRange(SSHHelper.GetAvailableSSHConnectionInfos().Select(item => new SSHConnectionViewModel(item))); } SupportedConnections = new ObservableCollection <IConnectionViewModel>(connections); OnPropertyChanged(nameof(SupportedConnections)); }
protected IConnection GetConnection() { ThreadHelper.ThrowIfNotOnUIThread(); if (this.sshConnection == null) { if (this.connectionInfo != null) { this.sshConnection = SSHHelper.CreateSSHConnectionFromConnectionInfo(connectionInfo); } } return(this.sshConnection); }
public static SSHConnection GetSSHConnection(string name) { ThreadHelper.ThrowIfNotOnUIThread(); ConnectionInfoStore store = new ConnectionInfoStore(); ConnectionInfo connectionInfo = null; StoredConnectionInfo storedConnectionInfo = store.Connections.FirstOrDefault(connection => { return(string.Equals(name, SSHPortSupplier.GetFormattedSSHConnectionName((ConnectionInfo)connection), StringComparison.OrdinalIgnoreCase)); }); if (storedConnectionInfo != null) { connectionInfo = (ConnectionInfo)storedConnectionInfo; } if (connectionInfo == null) { IVsConnectionManager connectionManager = (IVsConnectionManager)ServiceProvider.GlobalProvider.GetService(typeof(IVsConnectionManager)); if (connectionManager != null) { IConnectionManagerResult result; if (string.IsNullOrWhiteSpace(name)) { result = connectionManager.ShowDialog(); } else { ParseSSHConnectionString(name, out string userName, out string hostName, out int port); result = connectionManager.ShowDialog(new PasswordConnectionInfo(hostName, port, Timeout.InfiniteTimeSpan, userName, new System.Security.SecureString())); } if ((result.DialogResult & ConnectionManagerDialogResult.Succeeded) == ConnectionManagerDialogResult.Succeeded) { // Retrieve the newly added connection store.Load(); connectionInfo = store.Connections.First(info => info.Id == result.StoredConnectionId); } } else { throw new InvalidOperationException("Why is IVsConnectionManager null?"); } } return(SSHHelper.CreateSSHConnectionFromConnectionInfo(connectionInfo)); }