SFTP connection works in GUI but not via the .Net dll

Advertisement

MrAvgProgrammer
Joined:
Posts:
4

SFTP connection works in GUI but not via the .Net dll

I am trying to log into my SFTP server using User Name and Key Authentication only.

I have used the WinSCP GUI client to connect using the Putty Generated Private Key ppk file. I have successfully logged in and generated a session log:
. 2018-01-26 10:15:51.454 Initialised AES-256 SDCTR client->server encryption
. 2018-01-26 10:15:51.454 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2018-01-26 10:15:51.454 Initialised AES-256 SDCTR server->client encryption
. 2018-01-26 10:15:51.454 Initialised HMAC-SHA-256 server->client MAC algorithm
. 2018-01-26 10:15:51.564 Reading key file "C:\MyApp\bin\Debug\PrivateKey\TestPrivateKey.ppk"
! 2018-01-26 10:15:51.564 Using username "DDD56789".
. 2018-01-26 10:15:51.634 Server offered these authentication methods: publickey
. 2018-01-26 10:15:51.634 Offered public key
. 2018-01-26 10:15:51.664 Offer of public key accepted
! 2018-01-26 10:15:51.664 Authenticating with public key "imported-openssh-key"
. 2018-01-26 10:15:51.704 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "imported-openssh-key": ")
. 2018-01-26 10:15:55.464 Sent public key signature
. 2018-01-26 10:15:55.644 Access granted
. 2018-01-26 10:15:55.644 Opening session as main channel
. 2018-01-26 10:15:55.674 Opened main channel
. 2018-01-26 10:15:55.794 Started a shell/command
. 2018-01-26 10:15:55.844 --------------------------------------------------------------------------


I think go into my .Net application that references the WinSCPnet.dll (version 1.4.0.7781 via WinSCP v5.11.2 Automation folder).
using the same UserName,ppk file, and PassPhrase I receive the following error:

. 2018-01-26 10:18:01.289 Initialised AES-256 SDCTR client->server encryption
. 2018-01-26 10:18:01.289 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2018-01-26 10:18:01.289 Initialised AES-256 SDCTR server->client encryption
. 2018-01-26 10:18:01.289 Initialised HMAC-SHA-256 server->client MAC algorithm
. 2018-01-26 10:18:01.409 Reading key file "C:\MyApp\bin\Debug\TestPrivateKey.ppk"
. 2018-01-26 10:18:01.409 Unable to use this key file (unable to open file)
! 2018-01-26 10:18:01.409 Unable to use key file "C:\\MyApp\bin\Debug\TestPrivateKey.ppk" (unable to open file)
! 2018-01-26 10:18:01.409 Using username "DDD56789".
. 2018-01-26 10:18:01.439 Server offered these authentication methods: publickey
. 2018-01-26 10:18:01.439 Disconnected: No supported authentication methods available (server sent: publickey)

Here is the .Net Code for my Session connection.
[code]
' Setup session options
sessionOptions = New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
.HostName = strURL
.UserName = strUserName
.PortNumber = intPushPort 'typically 22
.GiveUpSecurityAndAcceptAnySshHostKey = True
.SshPrivateKeyPath = IO.Path.GetFullPath("TestPrivateKey.ppk")
.SshPrivateKeyPassphrase = "MyPassword"
End With

MySession = New Session
' Connect
MySession.SessionLogPath = "C:\MyApp\bin\Debug\winscp.log"
MySession.DebugLogPath = "C:\MyApp\bin\Debug\winscp_debug.log"

MySession.Open(sessionOptions)
[/code]

If anyone could point me in the right direction of what I am overlooking I would greatly appreciate it.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum