0

I was seeking for a free DLL for .net to handle SFTP connections.

I found out this project SharpSSH, but it lacks of documentation.

I spent a lot of time to figure how the dll works. I created a test project and I started to test different functions. Some functions are working such as deleting files.

I have a problem with putfile() function and getfile().

Here an example :

Dim ssh As SFTPUtil
ssh = New SFTPUtil("MY SERVER", "MY USER", "MY PW")
ssh.GetFile("/home/sftptest/test111.xml", "C:\\text.xml")

Note that the getfile() parameters are:

Public Sub GetFile(remotePath As String, localPath As String)

I step in the functions, but I didn't get the correct way to pass those parameters.

I dont really know if i should use slashes(/) or backslashes (). I know that Linux uses (/)

I noticed for example that the "C:\" has been transformed to "C:\\".

Just to mention that the SFTP is on a linux machine.

thank you.

7
  • remember that you also have SSHnet sshnet.codeplex.com Which is quite an improovement upon the java based sharpSSH Commented Aug 2, 2012 at 17:01
  • I try it, not able to make the connection. I call sftp = New SftpClient("server", "sftptest", "sftptest") which is SftpClient. And then, I do sftp.Connect(). And it fails. I got the net 4.0 dll version. I get the message error : No suitable authentication method found to complete authentication. Commented Aug 2, 2012 at 17:13
  • do you have a host to connect to? just to make sure use putty and connect to check if the connection exist. SftpClient sftp = New SftpClient(string IP, string Username, string Password); sftp.Connect(); Commented Aug 2, 2012 at 17:21
  • I tried with putty, it s working... Any other hints :) Commented Aug 2, 2012 at 17:29
  • I found out that I have to activate keyboard-interactive authentication. I ill find to figured it out. Commented Aug 2, 2012 at 17:35

3 Answers 3

6

Here's What I should have done (vb.net code) to establish the connection with THIS library (SSHnet), I did not use SharpSHH:

Private Sub ButtonAction_Click(sender As Object, e As System.EventArgs) Handles ButtonAction.Click

    Dim PasswordConnection = New PasswordAuthenticationMethod("test", "test")
    Dim KeyboardInteractive = New KeyboardInteractiveAuthenticationMethod("test")
    Dim ConnectionInfo = New ConnectionInfo("192.168.1.1", 22, "test", PasswordConnection, KeyboardInteractive)

    AddHandler KeyboardInteractive.AuthenticationPrompt, _
    Sub(_sender As Object, _e As Renci.SshNet.Common.AuthenticationPromptEventArgs)
        For Each prompt In _e.Prompts
            Debug.Print(prompt.Request)
            If Not prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) = -1 Then
                prompt.Response = "test"
            End If
        Next
    End Sub

    sftp = New SftpClient(ConnectionInfo)
    sftp.Connect()

    sftp.disconnect()
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

I have used the free SSH.NET but eventually used component pro sftp because SSH.NET lacked some advanced features and we needed quick support.
ComponentPro was a scam. All their libraries were stolen from other vendors and rebranded. Google it for more information or check their website. They got sued, lost, and are now out of business. Using their libraries might be a security and legal hazard.
1

This library is full of bugs. I downloaded version at 11/2012 and I have big problem even with simple function like Disconnect. Application will freeze and you have to restart it.

2 Comments

And 'This library...' is? Which one?
SharpSSH is full of bug. Use SSH.NET
0

I have some problem understanding what exactly you want so here is an example code from the SSH.NET package. (NOT SharpSSH)

string IP = "192.168.1.1", User = "Testuser", Pass = "123";
SftpClient sftp;

private void UploadFileSFTP()
    {
        sftp = new SftpClient(IP, User, Pass);
        sftp.Connect();
        Uploader();
        Downloader();
        sftp.Disconnect();
    }

string FilePath="C:\\folder\\", Filename = "Filename.extention", 
       DeliveryPath = "/tmp/";

private void Uploader()
    {
        using (var file = File.OpenRead(FilePath + Filename))
        {
            sftp.UploadFile(file, DeliveryPath + Filename);
        }
    }

//there is possibly a simpler way to download but this is how i did it.
string FromPath = "/tmp/testfile.txt", StoragePath = ""; 
private void Downloader()
    {
        if (File.Exists(StoragePath))
            File.Delete(StoragePath);
        if (!Directory.GetDirectories(Path.GetTempPath()).Contains("WorkFiles"))
        {
            Directory.CreateDirectory(Path.GetTempPath() + "WorkFiles");
        }

        StoragePath = Path.GetTempPath() + "WorkFiles\\testFile.txt";

        Int64 iSize = sftp.ReadAllBytes(FromPath).Length;
        Int64 iRunningByteTotal = 0;
        using (Stream streamRemote = sftp.OpenRead(FromPath))
        {
            using (Stream streamLocal = new FileStream(StoragePath, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                int iByteSize = 0;
                byte[] byteBuffer = new byte[iSize];
                while ((iByteSize = streamRemote.Read(byteBuffer, 0, byteBuffer.Length)) > 0)
                {
                    streamLocal.Write(byteBuffer, 0, iByteSize);
                    iRunningByteTotal += iByteSize;
                }
            }
        }
    }

4 Comments

I found out the solution : here, I have to set a keyboard-interactive authentication. I have the c# code, and I can't translate it to vb.net, lol.
I can't post out my answer because, I'm new and I don't have enough reputation, in other words, I'm a noob :p.
I wonder why they don't use sftp.DownloadFile() in this example ?
i didn't simply because this is a piece of code i had laying around.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.