Problems trying to connect throug vba


Barcelona (Spain)

Problems trying to connect throug vba

Hi, thank you for reading me. I apologize for my English (I'm Spanish) ... I'll try to do my best :-)

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:

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 = ""
        .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

    Set MySessionOptions = Nothing
    Set MySession = Nothing
    Exit Sub
    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 :-)
Saludos from Barcelona (Spain)
Last edited by happy on 2016-01-05 19:55; edited 1 time in total

Reply with quote



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

Reply with quote


You can post new topics in this forum