VB.Net - Cannot Open Session
I have been trying to write a method to connect to the server using the local machine private key file to the sFTP server. I can connect successfully using the WinSCP GUI.
Following are my codes. During the debug mode, it always stop at the session.open line and there isn't any useful error message given.
Try Dim sessionOptions As New SessionOptions With sessionOptions .Protocol = Protocol.Sftp .HostName = "xxx.xxx.xxx.xxx" .UserName = "xxxxx" .PortNumber = "22" .SshHostKeyFingerprint = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" .SshPrivateKeyPath = "x:\xxxx\xxxx.ppk" End With Using Session As Session = New Session Session.DisableVersionCheck = True Session.SessionLogPath = "D:\sftplog.log" ' Connect Session.Open(SessionOptions) Dim transferOptions As New TransferOptions transferOptions.TransferMode = TransferMode.Binary Dim transferResult As TransferOperationResult transferResult = Session.PutFiles("D:\Outbox\*", "/upload/xxxx/", False, transferOptions) ' Throw on any error transferResult.Check() ' Print results Dim transfer As TransferEventArgs For Each transfer In transferResult.Transfers Console.WriteLine("Upload of {0} succeeded", transfer.FileName) Next End Using Return 0 Catch e As Exception Console.WriteLine("Error: {0}", e) Return 1 End Try
Any help or tips would be greatly appreciated.
Thank you.