Help with using Renci SSH tool

Jul 13, 2013 at 9:09 PM
Hi All

I'm totally new with SSH and Renci specific.
I am looking for basic help and support in order to execute commands on Unix terminal.
I can execute simple ones like : "ls -ltr" or "pwd" , but when need to "cd /nfs/proj" .. or executing a perl script .. it just wont do .. :-(

The code i'm using -

Dim sshkey As New Renci.SshNet.PrivateKeyFile(System.Configuration.ConfigurationManager.AppSettings("SSH2key"))
    Dim conn2 As New Renci.SshNet.PrivateKeyConnectionInfo(modSSHHostName, modSSHUserName, sshkey)

    Dim sshClient As New Renci.SshNet.SshClient(conn2)

    'Need to hold the command
    Dim cmd As Renci.SshNet.SshCommand

    Using sshClient
        'connect to the server

        'Run the command and put the results into the cmd object. In this case
        'I am just running a directory list
        cmd = sshClient.CreateCommand("chdir /nfs/iil/proj")

        'Close the connection.
    End Using

Please assist me as much as you can , thanks in advance.
Jul 13, 2013 at 9:26 PM
What does "it just wont do" mean?
Exceptions? Hangs? Error-Messages?

The code you pasted won't work since chdir is not a Unix/Linux command.
Jul 14, 2013 at 6:30 AM
Thanks for reply.

The code I posted was in originally : cmd = sshClient.CreateCommand("cd /nfs/iil/proj") , I am trying any way to make it works.

When i'm saying "it just wont do" i meant - while trying to change directory using "cmd = sshClient.CreateCommand("cd /nfs/iil/proj")"
and then running cmd = sshClient.CreateCommand("pwd") I would expect to see the new path in the cmd.result - which I'm not.
Jul 14, 2013 at 6:43 AM
Thats because each Command is executed in a new Shell.
In your case I think the easiest way would be to combine your commands with "&&" or ";".

 cmd = sshClient.CreateCommand("cd /nfs/iil/proj && pwd");
 cmd = sshClient.CreateCommand("cd /nfs/iil/proj; pwd")
"&&" executes the following command just if the previous command succeeded
";" always executes the following commands

Another approach would be to use CreateShell() to write/read and use the input/output.
Jul 14, 2013 at 7:22 AM

It works (i'm sure you had no doubt .. :-))

Can you share a simple example of using CreateShell() ?
Jul 16, 2013 at 7:58 AM
How can I print on screen the printout of the command -- every time there is an output and not just a single print?