Post a reply

Options
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)

Options

Topic review

icekuhn

Thank you!

Thank you very much! You solved the problem :D

Greetings,

icekuhn
icekuhn

WinSCP.SessionRemoteException:connection unexpectedly closed

Hello everybody!

I have to connect to a SFTP-Server. The WinSCP GUI works fine, but my vb.net-code doesn't work.

CODE:

[color=green]Imports System

Imports WinSCP

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim i As Integer

        i = Upload()

        If i = 0 Then
            Label1.Text &= " Erfolg"
        Else
            Label1.Text &= " Fehlschlag"
        End If
    End Sub

    Public Function Upload() As Integer

        Try
            ' Setup session options
            Dim mySessionOptions As New SessionOptions
            With mySessionOptions
                .Protocol = Protocol.Sftp
                .HostName = "10.7.96.123"
                .UserName = "XXX_XXX"
                .Password = "YYY_YYY"
                ' .GiveUpSecurityAndAcceptAnySshHostKey = True
                ' .GiveUpSecurityAndAcceptAnySshHostKey = True
                .SshHostKeyFingerprint = "ssh-rsa 1024 62:d8:XX:28:ed:cf:9a:65:eb:ba:8d:2f:4b:ad:a5:63"
                .SshPrivateKeyPath = "C:\daten\WinSCPPortable\new\XXX_XXX.ppk"
                ' .FtpMode = FtpMode.Active
            End With


            Using mySession As Session = New Session
                mySession.SessionLogPath = "C:\daten\VB\File_Uploader_2\File Uploader 2\bin\Debug\test.log"
                ' Connect
                mySession.Open(mySessionOptions)

                ' Upload files
                Dim myTransferOptions As New TransferOptions
                myTransferOptions.TransferMode = TransferMode.Binary

                Dim transferResult As TransferOperationResult
                transferResult = mySession.PutFiles("c:\test\Hund\test.txt", "/upload/", False, myTransferOptions)

                ' Throw on any error
                transferResult.Check()

                ' Print results
                For Each transfer In transferResult.Transfers
                    Label3.Text &= " Upload of" & transfer.FileName & " succeeded"
                Next
            End Using

            Return 0
        Catch e As Exception
            Label3.Text &= " " & e.ToString
            Return 1
        End Try

    End Function

End Class[/color]


Exception at mySession.Open(mySessionOptions):

WinSCP.SessionRemoteException: Connection has been unexpectedly closed. Server sent command Exit Status 0. -> WinSCP.SessionRemoteException: Authentication log (see session log for Details):
Using useername: "XXX_XXX"
Authenticating with public key "YYY_YYY".

Authentication failed.




Log for the WORKING GUI_Connection:

--------------------------------------------------------------------------
WinSCP Version 4.2.9 (Build 938) (OS 6.1.7601 Service Pack 1)
Login time: Donnerstag, 30. April 2015 14:37:04
--------------------------------------------------------------------------
Session name: XXX_XXX@10.7.96.123
Host name: 10.7.96.123 (Port: 22)
User name: XXX_XXX (Password: No, Key file: Yes)
Tunnel: No
Transfer Protocol: SFTP (SCP)
Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
Proxy: none
SSH protocol version: 2; Compression: No
Bypass authentication: No
Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
SSH Bugs: -,-,-,-,-,-,-,-,-
SFTP Bugs: -,-
Return code variable: Autodetect; Lookup user groups: Yes
Shell: default
EOL: 0, UTF: 2
Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
Local directory: default, Remote directory: home, Update: No, Cache: Yes
Cache directory changes: Yes, Permanent: Yes
DST mode: 1
--------------------------------------------------------------------------
Looking up host "10.7.96.123"
Connecting to 10.7.96.123 port 22
Server version: SSH-2.0-OpenSSH_6.2
We believe remote version has SSH-2 ignore bug
Using SSH protocol version 2
We claim version: SSH-2.0-WinSCP_release_4.2.9
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 1024 62:d8:XX:28:ed:cf:9a:65:eb:ba:8d:2f:4b:ad:a5:63
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Reading private key file "C:\daten\WinSCPPortable\new\XXX_XXX.ppk"
Using username "XXX_XXX".
Offered public key
Offer of public key accepted
Authenticating with public key "YYY_YYY"
Prompt (2, SSH key passphrase, , Passphrase for key "YYY_YYY": )
Access granted
Opened channel for session
Started a shell/command
--------------------------------------------------------------------------
Using SFTP protocol.
Doing startup conversation with host.




Log for the vb.net-Connection, that doesn't work:

. 2015-04-30 14:09:29.921 --------------------------------------------------------------------------
. 2015-04-30 14:09:29.921 WinSCP Version 5.7.2 (Build 5316) (OS 6.1.7601 Service Pack 1 - Windows 7 Professional)
. 2015-04-30 14:09:29.921 Configuration: nul
. 2015-04-30 14:09:29.921 Log level: Normal
. 2015-04-30 14:09:29.921 Local account: VERWALTUNG\100kuhn
. 2015-04-30 14:09:29.921 Working directory: C:\daten\VB\SFTP_Upload\SFTP Upload\bin\Debug
. 2015-04-30 14:09:29.921 Process ID: 3188
. 2015-04-30 14:09:29.921 Command-line: "C:\daten\VB\SFTP_Upload\SFTP Upload\bin\Debug\winscp.exe" /xmllog="C:\Users\100kuhn\AppData\Local\Temp\wscp1A24.021A7086.tmp" /xmlgroups /nointeractiveinput /dotnet=572 /ini=nul /log="C:\daten\VB\File_Uploader_2\File Uploader 2\bin\Debug\test.log" /console /consoleinstance=_6692_44419000_536
. 2015-04-30 14:09:29.921 Time zone: Current: GMT+2, Standard: GMT+1 (Mitteleuropäische Zeit), DST: GMT+2 (Mitteleuropäische Sommerzeit), DST Start: 29.03.2015, DST End: 25.10.2015
. 2015-04-30 14:09:29.921 Login time: Donnerstag, 30. April 2015 14:09:29
. 2015-04-30 14:09:29.921 --------------------------------------------------------------------------
. 2015-04-30 14:09:29.921 Script: Retrospectively logging previous script records:
> 2015-04-30 14:09:29.921 Script: option batch on
< 2015-04-30 14:09:29.921 Script: batch on
< 2015-04-30 14:09:29.921 Script: reconnecttime 120
> 2015-04-30 14:09:29.921 Script: option confirm off
< 2015-04-30 14:09:29.921 Script: confirm off
> 2015-04-30 14:09:29.921 Script: option reconnecttime 120
< 2015-04-30 14:09:29.921 Script: reconnecttime 120
> 2015-04-30 14:09:29.921 Script: open sftp://XXX_XXX:***@10.7.96.123 -hostkey="ssh-rsa 1024 62:d8:XX:28:ed:cf:9a:65:eb:ba:8d:2f:4b:ad:a5:63" -privatekey="C:\daten\WinSCPPortable\new\XXX_XXX.ppk" -timeout=15
. 2015-04-30 14:09:29.921 --------------------------------------------------------------------------
. 2015-04-30 14:09:29.921 Session name: XXX_XXX@10.7.96.123 (Ad-Hoc site)
. 2015-04-30 14:09:29.921 Host name: 10.7.96.123 (Port: 22)
. 2015-04-30 14:09:29.921 User name: XXX_XXX(Password: Yes, Key file: Yes)
. 2015-04-30 14:09:29.937 Tunnel: No
. 2015-04-30 14:09:29.937 Transfer Protocol: SFTP
. 2015-04-30 14:09:29.937 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2015-04-30 14:09:29.937 Disable Nagle: No
. 2015-04-30 14:09:29.937 Proxy: none
. 2015-04-30 14:09:29.937 Send buffer: 262144
. 2015-04-30 14:09:29.937 SSH protocol version: 2; Compression: No
. 2015-04-30 14:09:29.937 Bypass authentication: No
. 2015-04-30 14:09:29.937 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2015-04-30 14:09:29.937 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2015-04-30 14:09:29.937 KEX: dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN
. 2015-04-30 14:09:29.937 SSH Bugs: A,A,A,A,A,A,A,A,A,A,A
. 2015-04-30 14:09:29.937 Simple channel: Yes
. 2015-04-30 14:09:29.937 Return code variable: Autodetect; Lookup user groups: A
. 2015-04-30 14:09:29.937 Shell: default
. 2015-04-30 14:09:29.937 EOL: 0, UTF: 2
. 2015-04-30 14:09:29.937 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2015-04-30 14:09:29.937 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2015-04-30 14:09:29.937 SFTP Bugs: A,A
. 2015-04-30 14:09:29.937 SFTP Server: default
. 2015-04-30 14:09:29.937 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2015-04-30 14:09:29.937 Cache directory changes: Yes, Permanent: Yes
. 2015-04-30 14:09:29.937 DST mode: 1
. 2015-04-30 14:09:29.937 --------------------------------------------------------------------------
. 2015-04-30 14:09:29.937 Looking up host "10.7.96.123"
. 2015-04-30 14:09:29.937 Connecting to 10.7.96.123 port 22
. 2015-04-30 14:09:29.952 Server version: SSH-2.0-OpenSSH_6.2
. 2015-04-30 14:09:29.952 Using SSH protocol version 2
. 2015-04-30 14:09:29.968 We claim version: SSH-2.0-WinSCP_release_5.7.2
. 2015-04-30 14:09:29.983 Doing Diffie-Hellman group exchange
. 2015-04-30 14:09:30.046 Doing Diffie-Hellman key exchange with hash SHA-256
. 2015-04-30 14:09:30.592 Verifying host key rsa2 0x23,XXXXXXXXXXXXXXXX 8bf13c0498b2905a XXXXXXXXXXXXXXXX 1383392fe95d10da XXXXXXXXXXXXXXXX 76d2f6924d96d575 XXXXXXXXXXXXXXXX 1c2734f2ddb84ac1 XXXXXXXXXXXXXXXX 23ce1fa87398e23a XXXXXXXXXXXXXXXX 8a5d9e0d5cc55b45 XXXXXXXXXXXXXXXX 2d9858454b878aeb XXXXXXXXXXXXXXXX e6a7ed454c38839d with fingerprint ssh-rsa 1024 62:d8:XX:28:ed:cf:9a:65:eb:ba:8d:2f:4b:ad:a5:63
. 2015-04-30 14:09:30.592 Host key matches configured key
. 2015-04-30 14:09:30.592 Host key fingerprint is:
. 2015-04-30 14:09:30.592 ssh-rsa 1024 62:d8:XX:28:ed:cf:9a:65:eb:ba:8d:2f:4b:ad:a5:63
. 2015-04-30 14:09:30.592 Initialised AES-256 SDCTR client->server encryption
. 2015-04-30 14:09:30.592 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2015-04-30 14:09:30.592 Initialised AES-256 SDCTR server->client encryption
. 2015-04-30 14:09:30.592 Initialised HMAC-SHA-256 server->client MAC algorithm
. 2015-04-30 14:09:30.639 Reading private key file "C:\daten\WinSCPPortable\new\XXX_XXX.ppk"
! 2015-04-30 14:09:30.639 Using username "XXX_XXX".
. 2015-04-30 14:09:30.654 Offered public key
. 2015-04-30 14:09:30.670 Offer of public key accepted
! 2015-04-30 14:09:30.670 Authenticating with public key "31100000_hund"
. 2015-04-30 14:09:30.670 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "YYY_YYY": ")
. 2015-04-30 14:09:30.670 Disconnected: Unable to authenticate


Does anyone have an idea, what is the Problem and how I can fix it???

Thank you and greetings,

icekuhn