Reputation: 31
For years the code below has worked. Then on April 11th it stopped. I noticed a warning in Visual Studio that the SSH.NET package was out of date, so I updated the package... still doesn't work.
Protected Sub FTPUpload(ByVal fileToBeUploaded As String, uploadedFilename As String)
Try
Using sftp As New SftpClient(sFtpServer, sFtpCreditUser, sFtpCreditPW)
sftp.Connect()
Dim upFile As Stream = File.OpenRead(fileToBeUploaded)
sftp.UploadFile(upFile, uploadedFilename)
upFile.Close()
sftp.Disconnect()
End Using
Catch ex As Exception
MsgBox(ex.Message & Chr(13) & Chr(10) & uploadedFilename)
End Try
End Sub
Exception thrown:
Renci.SshNet.Common.SshConnectionException in Renci.SshNet.dll
Renci.SshNet.Common.SshConnectionException: An established connection was aborted by the software in your host machine.
at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
at InvManager.Main.FTPUpload(String fileToBeUploaded, String uploadedFilename) in C:\Data\vb.net\InvManager2.3\InvManager\Main.vb:line 562
Have verified that credentials are still valid on server side.
FileZilla log showing SFTP connection from same Windows box running subject VB code to server:
Status: Connecting to server.com...
Response: fzSftp started, protocol_version=8
Command: open "[email protected]" 22
Command: Pass: ******
Status: Connected to server.com
Status: Retrieving directory listing...
Command: pwd
Response: Current directory is: "/home/server"
Command: ls
Status: Listing directory /home/server
Status: Directory listing of "/home/server" successful
Status: Disconnected from server
Would appreciate some help in getting this working again.
Upvotes: 2
Views: 3523
Reputation: 202088
It's difficult to debug SSH.NET library as it does hardly any logging. Try to find out, if there was any change in SSH server configuration. It's quite probable that the server changed the set set of allowed ciphers and other algos, what turned it incompatible with SSH.NET
You can also try to build SSH.NET out of its source code and add some logging/debug it, to see why it closes the connection.
Other than that, you should be able to solve it by switching to WinSCP .NET assembly, as WinSCP works for you. If your code is as simple as in your question, it would be trivial to switch.
Upvotes: 0
Reputation: 31
Never got the original code working again... Still not sure what changed with ssh.net that broke the code. But per @MartinPrikryl I re-wrote the code to use the WinSCP library instead of SSH.Net and the following code has us up and working again.
Protected Sub WinScpSFTPupload(ByVal fileToBeUploaded As String, uploadedFilename As String)
Try
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = sFtpServer
.UserName = sFtpCreditUser
.Password = sFtpCreditPW
.GiveUpSecurityAndAcceptAnySshHostKey = True
End With
Using session As New Session
session.Open(sessionOptions)
session.PutFiles(fileToBeUploaded, uploadedFilename).Check()
End Using
Catch ex As Exception
MsgBox(ex.Message & Chr(13) & Chr(10) & uploadedFilename)
End Try
End Sub ' Sub to WinSCP SFTP File
Upvotes: 1