This project is read-only.

Client connection pool

Sep 12, 2012 at 12:25 PM


Anyone has implemented connection pooling in their code when using SSH.Net? Would be great if someone could share their code.


Sep 12, 2012 at 12:40 PM
Edited Sep 12, 2012 at 1:34 PM

What do you mean? What context?

Sep 12, 2012 at 12:48 PM

instead of closing and disposing the connection, it can be released to a pool of connections. whenever a connection is needed, we can just obtain from the pool and need not open a new connection. This is useful as opening new connection is expensive and will save the overhead of creating connection.

Sep 12, 2012 at 12:56 PM
Edited Sep 12, 2012 at 1:34 PM

Why would a pool of connections help, when you only have 1 connection per ssh server?

What I think you mean having persistent connections, but across what?
Or am I missing it... 

Sep 12, 2012 at 1:29 PM

Sorry, maybe my understanding is wrong. Currently I'm using below code to download the files, when I iterate through all the files and do BeginDownloadFile, is it 1 connection and multiple channels or is it multiple connections each with its own channel?

I have just started exploring SSH.NET and wanted to implement within a window service. I was thinking about how to make efficient use of the connections; hope you can bear with me.


 using (var client = new SftpClient(this.connectionInfo))

                IEnumerable<SftpFile> listSftpFiles = client.ListDirectory(@"/SFTP/Outgoing/Test");
                List<IAsyncResult> listAsyncResults = new List<IAsyncResult>();

                foreach (SftpFile file in listSftpFiles)
                    if (file.IsRegularFile)
                        // try to download the file
                        MemoryStream instream = new MemoryStream();
                        DownloadFileAsyncState asyncState = new DownloadFileAsyncState();
                        asyncState.Stream = instream;
                        asyncState.Filename = file.FullName;
                        SftpDownloadAsyncResult asyncResult = (SftpDownloadAsyncResult)client.BeginDownloadFile(file.FullName, instream, new AsyncCallback(CompletedDownload), asyncState);

                while (!downloadAllCompleted)
                    downloadAllCompleted = !listAsyncResults.Exists(x => x.IsCompleted == false);

                    if (!downloadAllCompleted)


Sep 12, 2012 at 1:52 PM

It is 1 connection, multiple channels I believe.