Issue connecting to SFTP server, command exit status 0

Advertisement

JMPearson
Joined:
Posts:
5

Issue connecting to SFTP server, command exit status 0

I've been experimenting with the WinSCP .NET DLL. I've had success using it to connect to an FTP site, but not to an SFTP site. When I try to connect to the SFTP site I get the following message:

Connection has been unexpectedly closed. Server sent command exit status 0

This is my code:

Private Sub ConnectToSite()

    Dim strDebugLogFileName As String = ""
    Dim strSessionLogName As String = ""

    Try
        If oSession Is Nothing Then
            oSessionOptions = New SessionOptions
            oSession = New Session

            If Me.rbFTP.Checked = True Then
                With oSessionOptions
                    .Protocol = Protocol.Ftp
                    .HostName = "XXX.XXXXX.XX.XX"
                    .UserName = "XXXXXXXXXXX"
                    .Password = My.Settings.FTPaccess                        
                End With
            Else
                With oSessionOptions
                    .Protocol = Protocol.Sftp
                    .HostName = "XXXXXXXX.XXXX.XXX.XXX"
                    .UserName = "XXXXXXXXXXXXXXXX"
                    .Password = My.Settings.SFTPaccess                        
                    .SshHostKey = "ssh-xxx xxxx XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX"
                End With
            End If
            strDebugLogFileName = "\WinSCP_DebugLog_" & Format(Now, "yyyyMMdd") & "_" & Format(Now, "HHmmss") & ".txt"
            strSessionLogName = "\WinSCP_SessionLog_" & Format(Now, "yyyyMMdd") & "_" & Format(Now, "HHmmss") & ".txt"

            Using oSession
                oSession.DebugLogPath = Application.StartupPath & strDebugLogFileName                    
                oSession.SessionLogPath = Application.StartupPath & strSessionLogName                    
                oSession.Open(oSessionOptions)
            End Using

            Me.lblConnected.Visible = True
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message & vbCrLf & vbCrLf & ex.StackTrace, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

End Sub

When I look at the Debug file I'm creating it says that Authentication failed. My first reaction is that my password might be incorrect. I've double-checked it several times and it should be correct. I am able to connect to the SFTP site using the WinSCP GUI and FileZilla with no issues. Is there something in my code that I'm overlooking and not setting right?

Thanks!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Issue connecting to SFTP server, command exit status 0

There's no obvious error in the code. Can you post WinSCP_SessionLog_* as well as session log from the GUI?

Reply with quote

JMPearson
Joined:
Posts:
5

Here's the Session Log from the WinSCP GUI:

--------------------------------------------------------------------------
WinSCP Version 5.0.6 (Build 2074) (OS 6.1.7601 Service Pack 1)
Configuration: HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\
Local account: xxxxxxxxxxxx
Login time: Friday, March 23, 2012 7:08:41 AM
--------------------------------------------------------------------------
Session name: FMIS_EDS (Stored session)
Host name: xxxxxxxx.xxxx.xxx.xxx (Port: 22)
User name: xxxxxxxx_xxxx_xx (Password: No, Key file: No)
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: -
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: C:\, Remote directory: /FMIS/fmis_prod/Util_file, Update: Yes, Cache: Yes
Cache directory changes: Yes, Permanent: Yes
DST mode: 1
--------------------------------------------------------------------------
Looking up host "xxxxxxxx.xxxx.xxx.xxx"
Connecting to XXX.XX.XXX.XXX port 22
Server version: SSH-2.0-WRQReflectionforSecureIT_7.2.1 Build 736
Using SSH protocol version 2
We claim version: SSH-2.0-WinSCP_release_5.0.6
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-1
Verifying host key dss 2e96c87,,with fingerprint ssh-dss 1024 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
Host key matches cached key
Host key fingerprint is:
ssh-dss 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
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
Using username "xxxxxxxx_xxxx_xx".
Prompt (7, SSH password, , &Password: )
Sent password
Access granted
Opened channel for session
Started a shell/command
--------------------------------------------------------------------------
Using SFTP protocol.
Doing startup conversation with host.
Type: SSH_FXP_INIT, Size: 5, Number: -1
Type: SSH_FXP_VERSION, Size: 188, Number: -1
SFTP version 4 negotiated.
Unknown server extension check-file-handle=""
Unknown server extension check-file-name=""
Unknown server extension file-content-hash-1@ssh.com=""
Unknown server extension sftppermissiondisable@attachmate.com="-264175615"
Unknown server extension newline@vandyke.com="\r\n"
Server requests EOL sequence "\r\n".
We will use UTF-8 strings when appropriate
Changing directory to "/XXXX/XXXX_XXXX/XXXX_XXXX".
Getting real path for '/XXXX/XXXX_XXXX/XXXX_XXXX'
Type: SSH_FXP_REALPATH, Size: 34, Number: 3088
Type: SSH_FXP_NAME, Size: 43, Number: 3088
Real path is '/XXXX/XXXX_XXXX/XXXX_XXXX'
Trying to open directory "/XXXX/XXXX_XXXX/XXXX_XXXX".
Type: SSH_FXP_LSTAT, Size: 38, Number: 3335
Type: SSH_FXP_ATTRS, Size: 96, Number: 3335
Getting current directory name.
Listing directory "/XXXX/XXXX_XXXX/XXXX_XXXX".
Type: SSH_FXP_OPENDIR, Size: 34, Number: 3595
Type: SSH_FXP_HANDLE, Size: 10, Number: 3595
Type: SSH_FXP_READDIR, Size: 10, Number: 3852
Type: SSH_FXP_NAME, Size: 1173, Number: 3852
Type: SSH_FXP_READDIR, Size: 10, Number: 4108
Type: SSH_FXP_STATUS, Size: 19, Number: 4108
Status code: 1
Type: SSH_FXP_CLOSE, Size: 10, Number: 4356
Startup conversation with host finished.

And here is the WinSCP SessionLog generated from my .NET application:

. 2012-03-23 07:12:52.696 --------------------------------------------------------------------------
. 2012-03-23 07:12:52.696 WinSCP Version 5.0.6 (Build 2074) (OS 6.1.7601 Service Pack 1)
. 2012-03-23 07:12:52.696 Configuration: nul
. 2012-03-23 07:12:52.711 Local account: XXXXXXXXXXXX
. 2012-03-23 07:12:52.711 Login time: Friday, March 23, 2012 7:12:52 AM
. 2012-03-23 07:12:52.711 --------------------------------------------------------------------------
. 2012-03-23 07:12:52.711 Session name: XXXXXXXX_XXXX_XX@XXXXXXXX.XXXX.XXX.XXX (Ad-Hoc session)
. 2012-03-23 07:12:52.711 Host name: XXXXXXXX.XXXX.XXX.XXX (Port: 22)
. 2012-03-23 07:12:52.711 User name: XXXXXXXX_XXXX_XX (Password: Yes, Key file: No)
. 2012-03-23 07:12:52.711 Tunnel: No
. 2012-03-23 07:12:52.711 Transfer Protocol: SFTP
. 2012-03-23 07:12:52.711 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2012-03-23 07:12:52.711 Proxy: none
. 2012-03-23 07:12:52.711 SSH protocol version: 2; Compression: No
. 2012-03-23 07:12:52.711 Bypass authentication: No
. 2012-03-23 07:12:52.711 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2012-03-23 07:12:52.711 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2012-03-23 07:12:52.711 SSH Bugs: -,-,-,-,-,-,-,-,-,-
. 2012-03-23 07:12:52.727 SFTP Bugs: -,-
. 2012-03-23 07:12:52.727 Return code variable: Autodetect; Lookup user groups: -
. 2012-03-23 07:12:52.727 Shell: default
. 2012-03-23 07:12:52.727 EOL: 0, UTF: 2
. 2012-03-23 07:12:52.727 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2012-03-23 07:12:52.727 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2012-03-23 07:12:52.727 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2012-03-23 07:12:52.727 Cache directory changes: Yes, Permanent: Yes
. 2012-03-23 07:12:52.727 DST mode: 1
. 2012-03-23 07:12:52.727 --------------------------------------------------------------------------
. 2012-03-23 07:12:52.758 Looking up host "XXXXXXXX.XXXX.XXX.XXX"
. 2012-03-23 07:12:52.774 Connecting to XXX.XX.XXX.XXX port 22
. 2012-03-23 07:12:52.883 Server version: SSH-2.0-WRQReflectionforSecureIT_7.2.1 Build 736
. 2012-03-23 07:12:52.883 Using SSH protocol version 2
. 2012-03-23 07:12:52.883 We claim version: SSH-2.0-WinSCP_release_5.0.6
. 2012-03-23 07:12:52.930 Doing Diffie-Hellman group exchange
. 2012-03-23 07:12:52.992 Doing Diffie-Hellman key exchange with hash SHA-1
. 2012-03-23 07:12:53.257 Verifying host key dss ,0xa0988bd4d00165013eb2953a393c9d0642e96c87,,with fingerprint ssh-dss 1024 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
. 2012-03-23 07:12:53.257 Host key matches configured key
. 2012-03-23 07:12:53.257 Host key fingerprint is:
. 2012-03-23 07:12:53.257 ssh-dss 1024 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
. 2012-03-23 07:12:53.257 Initialised AES-256 SDCTR client->server encryption
. 2012-03-23 07:12:53.257 Initialised HMAC-SHA1 client->server MAC algorithm
. 2012-03-23 07:12:53.257 Initialised AES-256 SDCTR server->client encryption
. 2012-03-23 07:12:53.257 Initialised HMAC-SHA1 server->client MAC algorithm
! 2012-03-23 07:12:53.554 Using username "XXXXXXXX_XXXX_XX".
. 2012-03-23 07:12:53.616 Prompt (7, SSH password, , &Password: )
. 2012-03-23 07:12:53.616 Using stored password.
. 2012-03-23 07:12:53.616 Sent password
. 2012-03-23 07:12:55.644 Password authentication failed
! 2012-03-23 07:12:55.644 Access denied
. 2012-03-23 07:12:55.660 Prompt (7, SSH password, , &Password: )
. 2012-03-23 07:12:55.660 Disconnected: Unable to authenticate

One thing I did check was that the Fingerprint values agreed and they do. I appreciate your time looking into this.

Thanks!

Reply with quote

martin
Site Admin
martin avatar

There's no obvious issue in the logs.
So the only explanation is that your username and/or password does not match.
Are there any special characters in your username or password?

Reply with quote

JMPearson

Yes there is. The entity that controls the security to the SFTP server requires mixed case with at least two special characters. I'll double-check the values one more time just to make sure I have them entered properly.

Reply with quote

Advertisement

martin
Site Admin
martin avatar

JMPearson wrote:

Yes there is. The entity that controls the security to the SFTP server requires mixed case with at least two special characters. I'll double-check the values one more time just to make sure I have them entered properly.
Did you find anything?

Reply with quote

JMPearson
Joined:
Posts:
5

martin wrote:

JMPearson wrote:

Yes there is. The entity that controls the security to the SFTP server requires mixed case with at least two special characters. I'll double-check the values one more time just to make sure I have them entered properly.
Did you find anything?

I've been out of the office for a few days. I'm hoping to get back to this today. I will let you know. Thanks

Reply with quote

JMPearson
Joined:
Posts:
5

JMPearson wrote:

martin wrote:

JMPearson wrote:

Yes there is. The entity that controls the security to the SFTP server requires mixed case with at least two special characters. I'll double-check the values one more time just to make sure I have them entered properly.
Did you find anything?

I've been out of the office for a few days. I'm hoping to get back to this today. I will let you know. Thanks

I found my error and things are working now. Thank you for your help!

Reply with quote

JohanG
Guest

Inquiry to solution

Hi,

I see a solution was reached here but no indication of what it was has been posted. Do you mind clarifying the error you found to make this post more valuable to others facing the same issue?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Inquiry to solution

JohanG wrote:

I see a solution was reached here but no indication of what it was has been posted. Do you mind clarifying the error you found to make this post more valuable to others facing the same issue?
You better start a new thread for your problem and provide some information about it.

Reply with quote

Advertisement

You can post new topics in this forum