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

Feb 12, 2014 at 2:17 PM
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))
İ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)
                                textBox1.Text = textBox1.Text + "\r\n GENERATED SQL FOR " + key;
                //close client conn and dispose

Thank you for your concern,
Best Regards,

Feb 12, 2014 at 2:30 PM
Thats a server issue, not changeable on client side.

         Specifies the maximum number of open sessions permitted per
         network connection.  The default is 10.
Feb 12, 2014 at 3:07 PM
the screenshot is at after changing the parameter from 10 to 50 , error still continues.
Feb 12, 2014 at 3:28 PM
Edited Feb 12, 2014 at 3:33 PM
You have restarted the ssh-server?

Btw. IMHO your approach to increase the Limit is a wrong way to "fix" this.
Your code must handle those exceptions and have a kind of command-queue.
The limit exists for a reason, e.g. to prevent DOS attacks.
Feb 12, 2014 at 4:12 PM

Yes service restarted

kayhan yuksel

12 Şub 2014 18:28 tarihinde "da_rinkes" <[email removed]> yazdı:

From: da_rinkes

You have restarted the ssh-server?

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at

Feb 13, 2014 at 1:52 PM
We have resolved it with a workaround .
Used a list like 'List<SSHClient> clients' and added as many as NumOfSSHObjects.

NumOfSSHObjects = NumOfCommands / 10;
if ( (NumOfCommands % 10 ) > 0)
 NumOfSSHObjects = NumOfSSHObjects +1 ;

for (int i = 1; i <= NumOfSSHObjects ; i++)
            clients.Add(new SshClient(connectionInfo));
Feb 13, 2014 at 2:04 PM
Why not hack some code to make it independent of the MaxSession number?
Now you are just guessing its 10.
Don't know for what/who you are writing this code, but if your code hits a
server with a session limit of 5, then you do what?

This is a really bad workaround, cause you do a lot of heavy cpu asymetric crypto for nothing.
Feb 13, 2014 at 2:37 PM
if so , then use the ssh client to grep the MaxSessions variable from config file of the linux service and declare a parameter for it.
Currently this is a project to be used for inhouse purposes but the correct way to go is as you have pointed out. Do you have any other alternative ways in mind ?