Topic "Problems trying to connect throug vba"

Author Message
happy
[View user's profile]

Joined: 2015-12-17
Posts: 3
Location: Barcelona (Spain)
Hi, thank you for reading me. I apologize for my English (I'm Spanish) ... I'll try to do my best Smile

I'm doing some tests to connect to a host using VBA. There's no problem when I do in WinScp interface, but I'm having no success when I try using VBA.

This is the code I'm using:

Code:
Sub Conectar()
Dim MySession As New WinSCPnet.Session
Dim MySessionOptions As New WinSCPnet.SessionOptions

    On Error GoTo ErrorHandler
   
    MySession.SessionLogPath = CurrentProject.Path & "\Log\Log.txt"
    With MySessionOptions
        .Protocol = Protocol_Sftp
        .HostName = "ddddddddd.de.db.com"
        .UserName = "U111111"
        .Password = "MyPass"
        .PortNumber = 22
        .SshHostKeyFingerprint = "ssh-dss 1024 26:b7:f5:fa:0e:0c:71:e6:3a:6e:de:b7:a9:d7:26:41"
        .SshPrivateKeyPath = "C:\Users\U111111\privatekeywinscp.ppk"
    End With

    MySession.Open MySessionOptions

   
ExitProcedure:
    MySession.dispose
    Set MySessionOptions = Nothing
    Set MySession = Nothing
   
    Exit Sub
   
ErrorHandler:
    MsgBox Err.Number & " - " & Err.Description
    GoTo ExitProcedure

End Sub


The error fires in line MySession.Open MySessionOptions and is always the same "Connection has been unexpectedly closed. Server sent command exit status 0."

I asked for logging the "manual" session that executes from winscp interface and also asked for logging the "code" session. The "manual" logging session ends succesfulyy in this way

Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "U111111": ")
Response: "MyPass"
Sent public key signature
Access granted
Opening session as main channel
Opened main channel
Started a shell/command

The "code" logging goes well until

Prompt (3, SSH key passphrase, , Passphrase for key "U111111": )
Disconnected: Unable to authenticate

Any suggestions?

Thanks in advance Smile
Saludos from Barcelona (Spain)

Last edited by happy on 2016-01-05 19:55; edited 1 time in total
Advertisements
happy
[View user's profile]

Joined: 2015-12-17
Posts: 3
Location: Barcelona (Spain)
In case it may help, I have to say, in adition of what I exposed, that the Host I want to connect is inside a intranet and for accessing it, is necessary to generate public and private keys using Putty.

Thanks again
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
For a private key passphrase, use SessionOptions.SshPrivateKeyPassphrase, not SessionOptions.Password.

Note that SessionOptions.SshPrivateKeyPassphrase is deprecated and renamed to SessionOptions.PrivateKeyPassphrase since WinSCP 5.8 beta.

https://winscp.net/eng/docs/library_sessionoptions
happy
[View user's profile]

Joined: 2015-12-17
Posts: 3
Location: Barcelona (Spain)
That did the trick! Very Happy
Thank you very much!

Saludos from Barcelona
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License