Friday, November 26, 2010

SharpSSH: A Recompiled Version Compatible with Latest 64-bit Windows Server System

One of my recent project works is to integrate our CRM solution with a few data sources from different vendors, which requires me to develop an ETL component to download incremental update files from SFTP sites before processing them in our CRM application.

Since there is no support of SFTP in .NET framework itself, I have to look for alternative solution, so I ended up with the open source library called SharpSSH, which is pretty promising.

I was very happy that it worked with my first try on my local development VPC image which is on Windows Server 2003, 32-bit edition. But as soon as I promoted my ETL component to our UAT environment which is on Windows Server 2008 R2 (of course, 64-bit system), I ran into a "Bad Data" error when my component was trying to make connection to the SFTP site.

I did a little Google search, and found the solution here. I followed snowcoder's instructions, made a bunch of changes, and recompiled the library. Then everything worked for me on the 64-bit system.

Here are the download links, I hope that they could save you some time if you ever need this component (There were some errors in snowcode's original code he pasted there probably due to HTML formatting issue):

SharpSSH- Library (DLLs only)

SharpSSH- Source Code

[DISCLAIMER] I am by no means an expert on hardcore networking or cryptology programming (I have no intention to become one either at this moment), I am posting the recompiled library just for your convenience. All credit goes to Tamir Gal, snowcoder, and Mono Project. The license should stay as whatever it is originally.

[Further Note - Updated December 2011] There is another open source library in the community called SSH.NET, which you might want to check out. The library has got support for .NET 3.5, .NET 4.0, Windows Phone, Silverlight respectively. It looks very promising, and it has been actively maintained by the author.

Hope this helps!


  1. Hi Daniel,
    Thanks for this article. I tried to follow SnowCoder instruction but the code to put in verify(..) got from PuTTy project does not compile. There is no index in the sig byte-array management. For instance:

    int n = (int)((sig << 24) & 0xff000000) | (sig << 16) & 0x00ff0000) | ((sig << 8) & 0x0000ff00) | ((sig) & 0x000000ff);

    How did you fix that?
    Thanks in advance for your help.

  2. Hi Nicolas,

    You shouldn't need to do anything if you just download the two files that I have shared through my SkyDrive.


  3. You are right. I did not check those files thinking they were the originals. Sorry about that.

    It works like a Charm now.

    Thank you very much for your help.

  4. Hi,

    Can you please help me to provide some examples on how to redirect sharp ssh output to text file.

    I am trying to connect to unix box and execute commands and send back the output to Textbox. I want to parse the contents of text box and take some decision.

    I want to start/stop packages on Unix using C# dotnet program. Please help me with the some examples.

    String response;

    SshShell ssh = new SshShell("host", "username "password");

    ssh.WriteLine("ls -l");


    int readCount = 0;
    byte[] buff = new byte[1024];

    while (true)
    readCount = ssh.IO.Read(buff, 0, buff.Length);
    if (readCount == -1) break;
    response = System.Text.Encoding.Default.GetString(buff, 0, readCount);
    //Update your textbox with the response


    richTextBox1.Text = response;

    This is not giving proper output in textbox

  5. @Darshan, I am afraid that I am not able to provide any help for your particular implementation. I am not familiar with the approach to interact with a remote host using SshShell. On top of my head, I think you may want to debug the code to check if buff indeed has a stream. If that doesn't help, I would recommend posting your question on

  6. Is there any way to increase the buffer? I have a powershell script that uses this and returns the exptected results but with a line break as the results are too big for the buffer window. In putty I simply resize my window. Is there a programmatic way to resize?

    I tried sshshell.write(5) but that did nothing. Any ideas would help

  7. @Shai, I am not sure about this. You may want to ask the question on a PowerShell forum or, where you might have a better chance to get an answer to your question.

  8. Thanks for fixing this and publishing it. Big help!

  9. Hi,

    we have a 64-bit Biztalk server. When trying to transfer a xml file we receive this error in the Event log:

    Method: Blogical.Shared.Adapters.Sftp.SftpTransmitterEndpoint.ProcessMessage
    Error: [SftpTransmitterEndpoint] Unable to transmit file /test.xml.
    Inner Exception:
    Unable write file to /test.xml
    Method not found: 'Void Tamir.SharpSsh.SshBase.ConnectThroughProxy(Int32, System.String, Int32, System.String, System.String)'.. Changing any Send Port Transport properties might require the host to be restarted, as the connection pool might still have connections

    We don't have any Proxy settings, except HTTP Proxy port = 80 (mandatory setting). But still, the ConnectThroughProxy -method is called and apparently it's missing from the dll. Could you provide any help how to solve this issue?

    1. @vvv, I am not sure about this. Did you write the adapter yourself? If it is an adapter provided by third party, you may want to contact your vendor for a solution.

  10. Hi Daniel,

    I need the modified SharpSSH DLLs. But the links you have provided are no more active. Will you please make them available once again ??


    1. It is likely a temporary outage of Skydrive. If it doesn't come back, I can post it somewhere else.


    2. Can you please post it somewhere and make it available ??


    3. Just updated the links, it should work now.

    4. The links worked. Thanks a lot Daniel

  11. Hi Daniel,

    is there any mobile version of SharpSSH DLL?