Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

c# - SFTP SSH.NET DLL instead of SharpSSH

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...