Quantcast
Channel: SSH.NET Library
Viewing all 2955 articles
Browse latest View live

New Post: Double user login

$
0
0
I have a situation where i will login to a server using root user and password. but sometimes i will get a prompt "Do you want to login to primary console (yes or no)". we will give yes and will be prompted with password. So my question is if i use shellstream for this login . then can i use the SSHClient object to run commands with root user privilges. moreover is there any way to assign the ShellStream to SSHClient since the shell stream is created using SSHClient object.
        string commandResult = string.Empty;
        bool loginResult = false;
        string strIPAdress = txtIP.Text.ToString().Trim();
        string strUserName = txtUser.Text.ToString().Trim();// root user name 
        string strPassword = txtPassword.Text.ToString();// root password            
        string strCommand = txtCommand.ToString();
        SshClient client = null;
        try
        {
            client = new SshClient(strIPAdress, strUserName, strPassword);
            client.Connect();
            var shellStream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024);
            string reply = String.Empty;
            // Check if the Prompt contains Yes/No    
            MessageBox.Show(shellStream.ToString());
            var rep = shellStream.Expect("(yes or [no])");
            if (rep != null)
            {
                MessageBox.Show("Inside yes no check");
                shellStream.WriteLine("yes");
                rep = shellStream.Expect("Password:");
                if (rep != null)
                {
                    shellStream.WriteLine(strPassword );
                    // Check if the root user prompt
                    rep = shellStream.Expect(new Regex(@"[$#]"));
                    if (rep != null)
                    {
                        loginResult = true;
                    }
                    else
                    {
                        loginResult = false;                       
                    }
                }
                else
                {
                    loginResult = false;                       
                }
            }
            else
            {
                // Check if the root user prompt
                rep = shellStream.Expect(new Regex(@"[$#]"));
                if (rep != null)
                {
                    loginResult = true;
                }
                else
                {
                    loginResult = false;
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }
        finally
        {
           }          
        if (loginResult)
        {
            string commandName = txtCommand.Text.ToString();
            SshCommand command = client.CreateCommand(commandName);
            command.CommandTimeout = new TimeSpan(24, 0, 0);
            commandResult = command.Execute();               
                      }

    }

New Post: ssh.net $Path not returning everything

$
0
0
Hi,

in my code, i have this line that passes the command to the unix box
var cmd = ssh.CreateCommand(string.Format("pwd ; echo $PATH"));
what it returned is
/users01/myname
/usr/bin:/usr/sbin:/sbin

but when I type $PATH through Putty, I get a lot more than just "/usr/bin:/usr/sbin:/sbin" is there anything that I'm missing?

New Post: SSH connection issue

$
0
0
Gives error: Value cannot be null. Parameter name: data

New Post: Loop through files in SFTP folder

$
0
0
I am trying to write a routine to loop through all the files in a folder copy them of and then delete them from the SFTP Folder.
What would be the loop look like and methods I would need to use.

Thanks.

Created Unassigned: Bad behaviour with symbolic links [1856]

$
0
0
Symbolic link are most of time resolved because of the use of GetCanonicalPath().
This appears when calling GetAttributes() and when listing files.
The size of symbolic links in the SftpFileAttributes class appears to be the real size of the link, not the size of the target file/directory, so it is a mismatch.

New Post: SendKeepAlive exception close the application

$
0
0
Hi,

I'm having trouble with one exception in the dll that Renci is finalizing my application, menssage de error is "An established connection was aborted by the software in your host machine". With a little work I found that the error is in the SendKeepAlive in BaseClient.cs. When the connection is lost for some problem link such as the session is active and an error occurs when running SendKeepAlive. I put a error treatment (Try) to prevent my application finalized idevidamente, but the problem is in the treatment session that even continues to be active and terminated by sending the KeepAlive.
    /// <summary>
    /// Sends keep-alive message to the server.
    /// </summary>
    public void SendKeepAlive()
    {
        try
        {
            if (this.Session == null)
                return;

            if (!this.Session.IsConnected)
                return;

            this.Session.SendKeepAlive();
        }
        catch
        {
        }
    }

Created Unassigned: Command requires confirmation YES/NO [1863]

$
0
0
I need to execute command to restore router data but ssh command requires additional confirmation yes/no. In the putty I type additional command yes.

How can I execute restore command with confirmation?

New Post: TypeLoadException when using SFTPClient on Android with Xamarin Studio

$
0
0
I am referencing the Renci SSH library in my project and I am trying to execute the code. I get an error saying: UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Renci.SshNet.Session' from assembly 'Renci.SshNet, Version=2013.4.7.0, Culture=neutral, PublicKeyToken=null'.
Is anyone else having this problem?

New Post: PortForwardingL: local port 127.0.0.1:3306 cannot be bound.

$
0
0
session.setPortForwardingL(lPort, "localhost", rPort);

i get the=message at this stage can someone tell me why?

my firewall is off

New Post: SSH connection issue

$
0
0
Hello

Im a c# newbie, i used the code mentioned above with some modifications.

im trying to SSH into a linux busybox (unify Acces point)
the idea is to do a scheduled restart of the device, once every 24 hours.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.SshNet;
using Renci.SshNet.Common;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "10.150.110.64",
                   username = "admin",
                   password = "pass";
            int    port = 22;

            var connectionInfo = new KeyboardInteractiveConnectionInfo(host, port, username);
            connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
            {
                foreach (var prompt in e.Prompts)
                {
                    if (prompt.Request.Equals("Password: ",StringComparison.InvariantCultureIgnoreCase))
                    {
                        prompt.Response = password;
                    }
                }



            };

            using (var ssh = new SshClient(connectionInfo))
            {

                ssh.Connect();
                ssh.RunCommand("reboot");
                ssh.RunCommand("exit");

            }

        }
    }
}
when i try to run it. it returns with SshAuthenticationException was unhandled
my thought is that this ssh connection needs to accept the algorithm key when connection to a server first time.

is there any way to do this? or am i all wrong in my assumption?

enlighten me oh great masters ;)

Best Regards
mrjinx

New Post: ssh.net $Path not returning everything

$
0
0
With putty, you have an interactive shell, and many files are sourced (.bash_profile, .bashrc, .profile...).
With a non interactive shell (this is the case with CreateCommand()), a subset or none of those files are sourced, it depends on the registered shell with the user account, and the linux system (archlinux/debian).

What you can do, the most secure/sure way, is to edit your sshd_config file, add "PermitUserEnvironment yes", restart sshd, then create a file ~/.ssh/environment and set the environment variable you want.

If you can't do it, you can still prefix each command :
"pwd; echo $PATH" => "pwd; PATH=$PATH:/something echo $PATH"

New Post: SFTP Without username and public key

$
0
0
Hi, is it possible to connect using a public key without a username/password?

Created Unassigned: System.OutOfMemoryException when trying large files in sftp [1866]

$
0
0
Exception of type 'System.OutOfMemoryException' was thrown.
mscorlib
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at Renci.SshNet.SftpClient.InternalDownloadFile(String path, Stream output, SftpDownloadAsyncResult asyncResult, Action`1 downloadCallback)

-------
Multiple files of 400MB or 1GB files.
The entire file is in the stream object that could be the problem.
--------

New Post: ShellStream works - Sheel and Command do not work

$
0
0
Hi all,

I have to connect to a Linux machine which has an SSH server running on it. Connecting using ShellStream works fine:
ConnectionInfo connectionInfo = new PrivateKeyConnectionInfo ( "10.148.12.190", 22, "user", new PrivateKeyFile ( "id_rsa" ) );
SshClient sshClient = new SshClient ( connectionInfo );
sshClient.Connect ();

//////////////////////////////
ShellStream stream = sshClient.CreateShellStream ( "xterm", 80, 50, 1024, 1024, 1024 );
StreamReader reader = new StreamReader ( stream );
StreamWriter writer = new StreamWriter ( stream );
writer.AutoFlush = true;
string result = reader.ReadToEnd ();
Console.WriteLine ( result );
writer.WriteLine ( "TOPCELL" );
result = reader.ReadToEnd ();
Console.WriteLine ( result );
//////////////////////////////

sshClient.Disconnect ();
So far, so good!

But my original intention was to use SshCommand (because I need asynchronous execution). I used SshCommand in other projects before and never had any problems. But for some reason the SSH server does not see any byte of the command when I use this code:
ConnectionInfo connectionInfo = new PrivateKeyConnectionInfo ( "10.148.12.190", 22, "user", new PrivateKeyFile ( "id_rsa" ) );
SshClient sshClient = new SshClient ( connectionInfo );
sshClient.Connect ();

//////////////////////////////
SshCommand sshCommand = sshClient.CreateCommand ( "TOPCELL" );
string result = sshCommand.Execute ();
Console.WriteLine ( result );
//////////////////////////////

sshClient.Disconnect ();
When I debug this code sshCommand.Execute() never returns.

The developer of the Linux SSH server does not have any clue because sending the command via ShellStream and via putty works fine. Only Shell and SshCommand seem to have problems.

Any ideas what I could try to fix the problem?

I should mention that the SSH server sends some welcome string before I send the command. Is it possible that this confuses the SshClient somehow?

Thanks,
Oliver

New Post: Timeout value in ConnectionInfo - not used for Sftp?

$
0
0
When doing ListDirectory on an SftpClient where you are connected to a server that has silently disconnected (wlan down), SSH.NET will hang indefinately (I waited at least 20 minutes).

I have set a timeout on ConnectionInfo, but that does not change anything.
Setting OperationTimeout on the SftpClient works however.

So what does the Timeout property on ConnectionInfo do?
Is that only for the initial connection attempt?

New Post: Transferring from Server to Server Using Streams

$
0
0
I have two SFTP servers that both have SFTP servers installed. My question is, can my application, working as a middleman or controller, transfer files between these two servers without having to have my application pulldown and save the file on its local drive then pick it up and transfer it to its destination server?

New Post: Unable to connect to : Exception calling "Connect" with "0" argument(s): "No suitable authentication method found to complete authentication."

$
0
0
Hello,

I am trying to connect to an IBM Advanced Management Module (AMM) from Powershell, usinh the SSH-Sessions module, but I get this message:

Unable to connect to 10.220.12.220: Exception calling "Connect" with "0" argument(s): "No suitable authentication method found to complete authentication."

I can connect with Putty without problems. What can I do?

Thanks

New Post: Unable to connect to : Exception calling "Connect" with "0" argument(s): "No suitable authentication method found to complete authentication."

$
0
0
What about giving us some useful informations? Like commands/code? Maybe? :P

New Post: Need latest DLL for .net 3.5 framework

$
0
0
Hi ,

I can see so many changes has been done to the source code for various issues or suggestion , The binaries are dated 6th April 2013 , so could you please share or provide me a link for latest working stable dll

New Post: Unable to connect to : Exception calling "Connect" with "0" argument(s): "No suitable authentication method found to complete authentication."

$
0
0
Hello,

After doing Import-Module SSH-Sessions, I try to connect as follows:

PS C:> New-SshSession -ComputerName 10.220.12.220 -Username USERID -Password ***********
Unable to connect to 10.220.12.220: Exception calling "Connect" with "0" argument(s): "No suitable authentication method found to complete authentication."

The putty log shows me this:

2014-01-16 06:53:21 Looking up host "10.220.12.220"
2014-01-16 06:53:21 Connecting to 10.220.12.220 port 22
2014-01-16 06:53:21 Server version: SSH-2.0-OpenSSH_4.2
2014-01-16 06:53:21 Using SSH protocol version 2
2014-01-16 06:53:21 We claim version: SSH-2.0-PuTTY_Snapshot_2010_05_02:r8934
2014-01-16 06:53:21 Doing Diffie-Hellman group exchange
2014-01-16 06:53:21 Doing Diffie-Hellman key exchange with hash SHA-1
2014-01-16 06:53:23 Host key fingerprint is:
2014-01-16 06:53:23 ssh-rsa 2048 <some hex string>
2014-01-16 06:53:23 Initialised AES-256 CBC client->server encryption
2014-01-16 06:53:23 Initialised HMAC-SHA1 client->server MAC algorithm
2014-01-16 06:53:23 Initialised AES-256 CBC server->client encryption
2014-01-16 06:53:23 Initialised HMAC-SHA1 server->client MAC algorithm
2014-01-16 06:53:40 Access granted
2014-01-16 06:53:40 Opened channel for session
2014-01-16 06:53:40 Allocated pty (ospeed 38400bps, ispeed 38400bps)
2014-01-16 06:53:40 Started a shell/command

I am using the ssh.net library Renci.SshNet35.dll
Viewing all 2955 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>