0 votes
by (120 points)
edited

The following code is written in visual studio 2013 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Rebex.Net; using Rebex.TerminalEmulation; using System.Text.RegularExpressions; namespace rebex { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Ssh client = new Ssh();
        client.Connect("XX.XX.XX.XX");
        client.Login("app04","apiapp04");

        Shell s1 = client.StartCommand("cd bea/user_projects/domains/gds/gdsmeterlogs/gdssdk/Archive");
        string r = s1.ReadAll();
        Shell s2 = client.StartCommand("cat meter_sdk_nj09mhf0108.mhf.mhc.log.c_2014-02-12*");
        r += s2.ReadAll();
        string[] lines = Regex.Split(r, "\n");
        System.IO.File.WriteAllLines(@"C:\Users\ssameer\Downloads\test\abc.txt", lines);
        MessageBox.Show("done");
    }
}

} Why is the change directory(cd) command not working?How to change the directory in rebex ssh?

1 Answer

0 votes
by (147k points)
edited

Commands started using Ssh.StartCommand or Ssh.RunCommand are independent. They run over the same SSH session, but they are not executed from a single shell. The first command changes its current directory and ends, but the second command doesn't know anything about the environment of the first one.

Most Unix servers make it possible to use the ';' character to run multiple commands that share the same environment. Please try this:

    Shell s1 = client.StartCommand("cd bea/user_projects/domains/gds/gdsmeterlogs/gdssdk/Archive ; cat meter_sdk_nj09mhf0108.mhf.mhc.log.c_2014-02-12*");
    r += s1.ReadAll();
    string[] lines = Regex.Split(r, "\n");
    System.IO.File.WriteAllLines(@"C:\Users\ssameer\Downloads\test\abc.txt", lines);
    MessageBox.Show("done");
...