SFTP SSH.NET DLL而不是SharpSSH

我正在寻找.net的免费DLL来处理SFTP连接。

我发现了这个项目SharpSSH ,但它缺乏文档。

我花了很多时间来计算dll是如何工作的。 我创建了一个测试项目,然后开始测试不同的function。 某些function正在起作用,例如删除文件。

我有putfile()函数和getfile()的问题。

这是一个例子:

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

请注意,getfile()参数是:

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

我介入函数,但我没有得到正确的方法来传递这些参数。

我真的不知道我是否应该使用斜杠(/)或反斜杠()。 我知道Linux使用(/)

我注意到例如“C:\”已经转换为“C:\\”。

只是提到SFTP是在linux机器上。

谢谢。

这是我应该做的(vb.net代码)来建立与THIS库( SSHnet )的连接,我没有使用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 

这个库充满了bug。 我在11/2012下载了版本,即使使用像Disconnect这样的简单function,我也遇到了很大问题。 应用程序将冻结,您必须重新启动它。

我有一些问题需要了解你想要什么,所以这里是SSH.NET包的示例代码。 (不是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; } } } }