sample code to connect to SFTP just like WinSCP? (wodSFTP / wodSFTP.NET / wodSFTPdll)

by mark.azali, (9 days ago)

I am trying to connect to an SFTP server that uses PPK. I am getting an error message of authentication failed at connectedevent

The information I have: hostname, login, pass, remote path, and the PPK file
sample vb

sftp1.hostname = "xxxxx"
sftp1.login = "xxxxx"
sftp1.password = "xxxxx"
Dim test As New WeOnlyDo.Security.Cryptography.Keys
test.Load("myprivatekey.ppk")
Sftp1.Authentication = WeOnlyDo.Client.SFTP.Authentications.Both
Sftp1.PrivateKey = test.PrivateKey(WeOnlyDo.Security.Cryptography.SSHKeyTypes.RSAKey)
sftp1.connect()

Is there a setting /event I'm missing to accept the fingerprint of server?

sample code to connect to SFTP just like WinSCP?

by Jasmine, (9 days ago) @ mark.azali

Hi,
I don't see full code. Whsat error do you get? Perhaps setting Blocking property to True is important in your case, since you seem to be using component in synchronous way.

But please try with our samples first.

Jasmine

sample code to connect to SFTP just like WinSCP?

by markazali, (9 days ago) @ Jasmine

here is sample code with private information removed. Setting blocking = true did not help

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Try

'Authenticate with server using hostname, login, password.
wodSFTP1.Hostname = "utftp.xxxxx.com"
wodSFTP1.Login = "xxxxx"
wodSFTP1.Password = "xxxxxx"
wodSFTP1.Port = 22
wodSFTP1.Blocking = True
Dim key As New WeOnlyDo.Security.Cryptography.Keys
wodSFTP1.Authentication = SFTP.Authentications.PublicKey
key.Load("myprivatekey.ppk")

wodSFTP1.Authentication = WeOnlyDo.Client.SFTP.Authentications.Both

wodSFTP1.PrivateKey = key.PrivateKey(WeOnlyDo.Security.Cryptography.SSHKeyTypes.RSAKey)


wodSFTP1.Connect()

'After connection with server is successful download the file on your local system using only one method.
'wodSFTP1.GetFile("c:\", "/home/somepath/somefile.txt")

Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub wodSFTP1_ConnectedEvent(Sender As Object, Args As SFTP.ConnectedArgs) Handles wodSFTP1.ConnectedEvent
If (Args.Error Is Nothing) Then
'GetFiles Method is used to download complete directory structure of some folder on server to local disk.
'In combination with LoopItem Event we can download only specific filenames.
wodSFTP1.GetFiles("c:\somelocalfolder", "/home/somefolder", 0)
Else
'Receive connection error here. If there were any.
MsgBox("Connected Error: " + Args.Error.Message)
End If
End Sub

Private Sub wodSFTP1_DisconnectedEvent(Sender As Object, Args As SFTP.ConnectedArgs) Handles wodSFTP1.DisconnectedEvent

End Sub

sample code to connect to SFTP just like WinSCP?

by Jasmine, (9 days ago) @ markazali

Hi,
you must provide more info what exactly happens. "did not help" doesn't really help us also - I don't what error you got, how far it has reached etc..
Errors are usually self descriptive - which one do you get?

Jasmine

sample code to connect to SFTP just like WinSCP?

by markazali, (9 days ago) @ Jasmine

at the connectedevent, this is being logged

Connected Error: Authentication with the server failed.
Exception thrown: 'WeOnlyDo.Exceptions.SFTP.AuthorizationException' in WeOnlyDo.Client.SFTP.dll
WeOnlyDo.Exceptions.SFTP.AuthorizationException: Authentication with the server failed.
at A.B.f()
at A.B.A(IAsyncResult , Boolean )
at WeOnlyDo.Client.SFTP.Connect()
at WindowsApp1.Form1.Button2_Click(Object sender, EventArgs e)
The thread 0x93a4 has exited with code 0 (0x0).
The thread 0x5474 has exited with code 0 (0x0).
The thread 0xb4c4 has exited with code 0 (0x0).
Connected Error: Authentication with the server failed.

sample code to connect to SFTP just like WinSCP?

by Jasmine, (9 days ago) @ markazali

I see.

Well, I can't say without trying. If WinSCP works then wodSFTP should too - not much client can do if server rejects him.
Only thing I notice is that you use Pubkey authentication, and you have specified password also - no need to specify it.. Or you wanted to use both for authentication?

If all fails, can you send all the details to our techsupport so we can try to connect there and debug the issue? This is simple issue and has to work.

Regards,
Jasmine

sample code to connect to SFTP just like WinSCP?

by markazali, (9 days ago) @ Jasmine

shall I email the general tech support email or do you have specific one to use?

sample code to connect to SFTP just like WinSCP?

by Jasmine, (9 days ago) @ markazali

Hi,

techsupport - at - weonlydo . com - one you already did contact few days ago.

Jasmine

sample code to connect to SFTP just like WinSCP?

by markazali, (9 days ago) @ Jasmine

I have sent an email

sample code to connect to SFTP just like WinSCP?

by Jasmine, (9 days ago) @ markazali

Hi,

yes, but there's no keys or attachments inside.

Regards,
Jasmine

sample code to connect to SFTP just like WinSCP?

by mark.azali, (9 days ago) @ Jasmine

I sent another email with attachment. Please let me know if it is received.

sample code to connect to SFTP just like WinSCP?

by Jasmine, (9 days ago) @ mark.azali

Hi,

sorry, no attachments arrived. You can attach it directly to the ticket that was open for you.

Jasmine