Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


That did the trick! :D
Thank you very much!

Saludos from Barcelona

Re: Problems trying to connect throug vba

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.

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

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)