Quantcast
Viewing all articles
Browse latest Browse all 1729

New Post: Problems changing directory with sftpClient.ChangeDirectory() after getting directory through SSH command

Hi,

I have the following script:
string workingDirectory;
using (var client = new SshClient(ssh_host, ssh_username, ssh_password))
{
    try
    {
        client.Connect();
        if(client.IsConnected)
        {
            SshCommand getSSHWorkingDirectory = client.RunCommand("pwd");
            workingDirectory = getSSHWorkingDirectory.Result;
            // RESULT: /customers/5/7/9/domain.com/httpd.private
            using (var sftpClient = new SftpClient(ssh_host,ssh_username,ssh_password))
            {
                Console.WriteLine(sftpClient.WorkingDirectory);
                // RESULT: /customers/5/7/9/domain.com/httpd.www <- NOTE httpd.www

                sftpClient.ChangeDirectory(workingDirectory);
                // ERROR: Renci.SshNet.Common.SftpPathNotFoundException: No such file

            }
        }
    }
    catch(Exception ex)
    {
        Messagebox.Show(ex.Message);
    }
}
How can i get passed this error? The path does indeed exist.
Now i am using a really ugly iteration through server folders to find the correct files i in the first place generated through a previous SshClient session.

Any help is much appreciated! :-)

Viewing all articles
Browse latest Browse all 1729

Trending Articles