Exemplo n.º 1
0
        private void connToServerAndDownloadBtn_Click(object sender, EventArgs e)
        {
            var ip     = ipTextBox.Text;
            var port   = Int32.Parse(portTextBox.Text);
            var login  = loginTextBox.Text;
            var passwd = passwdTextBox.Text;

            try
            {
                using (var client = new Renci.SshNet.ScpClient(ip, port, login, passwd))
                {
                    client.Connect();
                    client.Download("/var/lib/jboss/acm/topology.structure",
                                    new FileInfo(
                                        Path.Combine(Path.GetDirectoryName(
                                                         Assembly.GetExecutingAssembly().Location), @"Data\topology.structure"))
                                    );
                    client.Disconnect();
                }

                MessageBox.Show("Файл успешно загружен и готов к работе!", "Информация",
                                MessageBoxButtons.OK);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\nПроблемы с подключением. Проверьте работопоспособность" +
                                " сервера и правильность введенных данных", "Ошибка", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     ssh?.Dispose();
     scp?.Dispose();
     ssh = null;
     scp = null;
 }
Exemplo n.º 3
0
 public void Close()
 {
     try { ssh?.Disconnect(); } catch { }
     try { scp?.Disconnect(); } catch { }
     ssh = null;
     scp = null;
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 private Renci.SshNet.ScpClient GetScpClient()
 {
     if (scp == null)
     {
         scp = new Renci.SshNet.ScpClient(host, user, GetKeyFiles());
     }
     if (!scp.IsConnected)
     {
         scp.Connect();
     }
     return(scp);
 }