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

New Post: PortForwading Bug

$
0
0
I read last comments, but I'm not able to solve.

I do this next test.
I made a TEMP database on two sql servers availables with 2 freeSSH servers for each network.
I create a temp users for SSH server
With a blank Windows form project I draw 2 buttons and 2 richtectbox. I used VB.

From Click event on button 1 I write to conenct to server 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        RichTextBox1.AppendText("Connecting...." & vbNewLine)

      

        Dim client As SshClient = New SshClient("77.73.166.66", 1443, "tempuser", "tempuser")
        Try
            client.Connect()
            RichTextBox1.AppendText("Connected to 77.73.166.66:1443" & vbNewLine)
            Dim fw As ForwardedPortLocal = New ForwardedPortLocal("127.0.0.1", 14444, "192.168.1.3", 1433)
            client.AddForwardedPort(fw)
            fw.Start()

            Dim query As String = "select * from temp"
            Dim CadenaDEconexion As String = "data source =127.0.0.1,14444; initial catalog = TEMP; user id = tempuser; password = tempuser; MultipleActiveResultSets=True"

            Dim cnn As New SqlConnection(CadenaDEconexion)
            Dim cmd As New SqlCommand
            Dim rdr As SqlDataReader
            cnn.Open()
            cmd.Connection = cnn
            cmd.CommandText = query
            rdr = cmd.ExecuteReader

            While rdr.Read
                RichTextBox1.AppendText(rdr(0) & " " & rdr(1) & vbNewLine)
            End While

            rdr.Close()
            cnn.Close()

            fw.Stop()
            client.RemoveForwardedPort(fw)
            client.Disconnect()
        Catch ex As Exception

        End Try
    End Sub
On the Click from button2 to connect to server 2


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        RichTextBox2.AppendText("Connecting...." & vbNewLine)
        Dim client As SshClient = New SshClient("77.73.161.57", 1443, "tempuser", "tempuser")
        Try
            client.Connect()
            RichTextBox2.AppendText("Connected to 77.73.161.57:1443" & vbNewLine)
            Dim fw As ForwardedPortLocal = New ForwardedPortLocal("127.0.0.1", 14444, "192.168.1.3", 1433)
            client.AddForwardedPort(fw)
            fw.Start()

            Dim query As String = "select * from temp"
            Dim CadenaDEconexion As String = "data source =127.0.0.1,14444; initial catalog = TEMP; user id = tempuser; password = tempuser; MultipleActiveResultSets=True"

            Dim cnn As New SqlConnection(CadenaDEconexion)
            Dim cmd As New SqlCommand
            Dim rdr As SqlDataReader
            cnn.Open()
            cmd.Connection = cnn
            cmd.CommandText = query
            rdr = cmd.ExecuteReader

            While rdr.Read
                RichTextBox2.AppendText(rdr(0) & " " & rdr(1) & vbNewLine)
            End While

            rdr.Close()
            cnn.Close()

            fw.Stop()
            client.RemoveForwardedPort(fw)
            client.Disconnect()


        Catch ex As Exception

        End Try
    End Sub
TEST steps:

I Start application:
Button1 Connect to Server1----- OK
Query restult------>
Connected to 77.73.166.66:1443
Full 1
My name
Close application

Start application
Button2 Connect to server2 ----- OK
Query result ----->
Full 2
My name 2
Close application


Start application
Button1 Connect to server 1 ---> ok
Query Result --->
Full 1
My name
WITHOUT close application
Button2 Connecto to server 2 ---> Client.IsConnected shows True
but...Query result--->
Full 1
My name


Returns the results from Client1.

You can use my servers data to try if you need.

What I'm doing wrong??

New Post: PortForwading Bug

$
0
0
You are using the same port for both LocalForwards.
Usually you should get an exception... but I'm bad in reading VB

Change the port 14444 in Button2_Click to something different, e.g 14445.

Commented Issue: Remote File exists not working [1574]

$
0
0
I've tried to use sftp.Exists(String) do not work for files. Already tested for file and for directory. Directory work well, but files are not recognized.
Comments: ** Comment from web user: sscoder **

Is there a fix for this yet? Will the above mentioned solution work?

Commented Issue: Remote File exists not working [1574]

$
0
0
I've tried to use sftp.Exists(String) do not work for files. Already tested for file and for directory. Directory work well, but files are not recognized.
Comments: ** Comment from web user: oeriksen **

In my project I have created the following little function and I havn't had any troubles with servers I connect to. SftpClient.GetAttributes() is using RequestLStat like I mentioned in my earlier comment. In my opinion it's better than the solution mmoufakkir2 is talking about which is from an earlier version of SshNet that was replaced because some server didn't close the file handle which caused problems when you wanted to delete the file. And it's better than current solution which doesn't work on all servers.
```
public bool Exists(string remotefilepath)
{
try
{
_sftpClient.GetAttributes(remotefilepath);
}
catch (SftpPathNotFoundException)
{
return false;
}
return true;
}
```

New Post: SftpClient.Exists always return true

$
0
0
I've created this little function in my project and I don't have any problems.
public bool Exists(string remotefilepath)
{
    try
    {
        _sftpClient.GetAttributes(remotefilepath);
    }
    catch (SftpPathNotFoundException)
    {
        return false;
    }
    return true;
}

Commented Issue: Remote File exists not working [1574]

$
0
0
I've tried to use sftp.Exists(String) do not work for files. Already tested for file and for directory. Directory work well, but files are not recognized.
Comments: ** Comment from web user: sscoder **

I tried oeriksen's solution and it is working fine. Thank you so much!!.

Commented Unassigned: "Exists" function does not work [1696]

$
0
0
"Exists" function does not work in new version of SFTP client. Earlier this worked.
Comments: ** Comment from web user: djpirra **

I am having the same issue.
Did anyone looked into it?
Can this be because of Windows vs Linux server versions?

Does the fullpath comparing with "\" or "/" makes a difference?

Thank you

New Post: PortForwading Bug

$
0
0
But the forwading port is closed before reopen, I think this should works fine.

in fact, I'm using a Chilkat SSH trial component while we find a solution for SSH.net, and works very well just like that.

New Post: PortForwading Bug

$
0
0
Hi,

I could reproduce your issue with your code and credentials.
The problem in fact isn't SSH.Net. Its the SqlConnection pool.

To make it clear, the problem is your connection/query/result seems to get cached.
So same connection/query, result is returned from the cache not the actual server.

If you clear the pool, in C# it's "SqlConnection.ClearAllPools()" or "SqlConnection.ClearPool(sql)", everything is fine.

My Code:
using System;
using System.Data.SqlClient;
using Renci.SshNet;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string ip1 = "77.73.166.66";
            string ip2 = "77.73.161.57";
            try
            {
                GetData(ip1);
                GetData(ip2);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            Console.WriteLine("Press Enter to exit");
            Console.ReadLine();
        }

        private static void GetData(string ip)
        {
            Console.WriteLine("Getting Data from: " + ip);
            var client = new SshClient(ip, 1443, "tempuser", "tempuser");
            client.Connect();

            var fw = new ForwardedPortLocal("127.0.0.1", 14444, "192.168.1.3", 1433);
            client.AddForwardedPort(fw);
            fw.Start();

            var query = "select * from temp";
            var foo = "data source =127.0.0.1,14444; initial catalog = TEMP; user id = tempuser; password = tempuser; MultipleActiveResultSets=True";

            var sql = new SqlConnection(foo);
            var cmd = new SqlCommand();

            sql.Open();
            cmd.Connection = sql;
            cmd.CommandText = query;

            var reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(reader[0] + " " + reader[1]);
            }

            reader.Close();
            sql.Close();

            // this fixes the issue
            //SqlConnection.ClearAllPools();
            SqlConnection.ClearPool(sql);


            fw.Stop();
            client.RemoveForwardedPort(fw);
            client.Disconnect();
        }
    }
}
Also if you don't clear the pool, you can send sql queries to localhost:14443 without having any connection to it and
get the cached result.

Caching is so awesome... ;)

New Post: netconfig on juniper solution

$
0
0
OK. I think I got this figured out I was loading an older version of the Binary. I am no longer getting the error.

would anyone be able to post an example of an RPC message? I am sending the following:

<rpc><get-chassis-inventory><detail/></get-chassis-inventory></rpc>

all I get as return:

rpc-reply

New Post: netconfig on juniper solution

$
0
0

I do

static Renci.SshNet.NetConfClient nc;

nc =newNetConfClient(ip,user, pw);

nc.AutomaticMessageIdHandling =false;

nc.OperationTimeout =newTimeSpan(0, 0, 60);

nc.Connect();

System.Xml.XmlDocument c = new System.Xml.XmlDocument();

System.Xml.XmlDocument d = new System.Xml.XmlDocument();

c.PreserveWhitespace =false;

c.LoadXml<rpc><get-chassis-inventory/></rpc>");

d = nc.SendReceiveRpc(c);

Source code checked in, #34458

$
0
0
Fix build when targeting .NET Framework 3.5 as Func only supports covariance on .NET Framework 4.0 and higher.

Source code checked in, #34459

$
0
0
Modify Renci.SshNet.WindowsPhone project to target WP 7.1 again instead of 8.0. The upgrade of the solution and project files to VS 2013 caused this regression.

Source code checked in, #34460

$
0
0
Enable source control binding for all projects.

Source code checked in, #34461

$
0
0
Remove Test project from solution as its a local project which is only used by Oleg.

New Post: Communication with OpenSSH windows

$
0
0
I am trying to connect to SSH server (OpenSSH Windows) but though it says its connected, none of the commands work.

The output when logging in via Putty looks as follows:

_login as: administrator
                        ****USAGE WARNING****
This is a private computer system. This computer system, including all
related equipment, networks, and network devices (specifically including
Internet access) are provided only for authorized use. This computer system
may be monitored for all lawful purposes, including to ensure that its use
is authorized, for management of the system, to facilitate protection against
unauthorized access, and to verify security procedures, survivability, and
operational security. Monitoring includes active attacks by authorized entities
to test or verify the security of this system. During monitoring, information
may be examined, recorded, copied and used for authorized purposes. All
information, including personal information, placed or sent over this system
may be monitored.

Use of this computer system, authorized or unauthorized, constitutes consent
to monitoring of this system. Unauthorized use may subject you to criminal
prosecution. Evidence of unauthorized use collected during monitoring may be
used for administrative, criminal, or other adverse action. Use of this system
constitutes consent to monitoring for these purposes.


administrator@172.203.131.64's password:
Last login: Tue Feb 11 15:37:38 2014
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\Documents and Settings\Administrator>
_

Can someone please help me login and execute a command such as "dir" or "cd\" on the server?

New Post: Communication with OpenSSH windows

$
0
0
No Code, No Exceptions, No Service. Sorry ;)

New Post: Configuration Error Exception using Renci.SshNet in a CGI application

$
0
0
Hi,
I included Renci.SshNet in a CGI application in order to implement an SFTP client in it, but when I invoke the Connect() method on SftpClient object I get this System.Configuration.ConfigurationErrorsException:

Configuration System failed to initialize - in System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
in System.Configuration.ConfigurationManager.PrepareConfigSystem()
in System.Configuration.ConfigurationManager.GetSection(String sectionName)
in System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
in System.Net.Configuration.SettingsSectionInternal.get_Section()
in System.Net.NetworkingPerfCounters..ctor()
in System.Net.NetworkingPerfCounters.CreateInstance()
in System.Net.NetworkingPerfCounters.get_Instance()
in System.Net.Sockets.Socket.InitializeSockets()
in System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse)
in System.Net.IPAddress.TryParse(String ipString, IPAddress& address)
in Renci.SshNet.Extensions.GetIPAddress(String host)
in Renci.SshNet.Session.SocketConnect(String host, Int32 port)
in Renci.SshNet.Session.Connect()

I resolved this exception adding a CGI mapping handler to the site where my CGI app runs under IIS6, but this workaround doesn't works on IIS7.

Regards.
Emanuele.

New Post: how to open more than 10 channels using a single connection object for multithreading

$
0
0
Can we declare the number of channels that can be used via single connection object?
the way we use it is :
var connectionInfo = new PasswordConnectionInfo(strServerIP, strUsername, strPassword);
        connectionInfo.Timeout = TimeSpan.FromSeconds(30);
            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
İf we try to open more than 10 threads , the error :
Failed to open a channel after 10 attempts

The block that is used for multithreading is:
   //global count 
                foreach (string key in CmdGenerators.Keys)
                {
                    textBox1.Text = textBox1.Text + "\r\n[" + DateTime.Now + "] Entry point for thread : " + key;
                    SshCommands[key] = client.CreateCommand(CmdGenerators[key].ToString()); // Perform long running task
                    AsyncResults[key] = SshCommands[key].BeginExecute(delegate(IAsyncResult ar)
                    {
                        Boolean temp = true;
                    }, null);
                }

                //set flag to control the state of the async processes
                //int totalFinished = 0;
                List<string> FinishedKeys = new List<string>();
                while (FinishedKeys.Count() != AsyncResults.Count())
                //while (AsyncResults.Count() != 0)
                {

                    foreach (string key in AsyncResults.Keys)
                    {
                        if (FinishedKeys.Any(key.Contains) == false)
                        {
                            if (AsyncResults[key].IsCompleted)
                            {
                                FinishedKeys.Add(key.ToString());
                                SshCommands[key].EndExecute(AsyncResults[key]);
                                SshCommands[key].Dispose();
                                textBox1.Text = textBox1.Text + "\r\n GENERATED SQL FOR " + key;
                            }
                        }
                    }
                }
                //close client conn and dispose
                client.Disconnect();
                client.Dispose();

Thank you for your concern,
Best Regards,

Kayhan YÜKSEL

New Post: how to open more than 10 channels using a single connection object for multithreading

Viewing all 2955 articles
Browse latest View live