SFTP The server has closed the connection.

+1 vote
asked Sep 24 by Prabhakar (500 points)

Exception "The server has closed the connection." is thrown with
_sftp.Login(username, pwd);
Below settings are applied.
_sftp.Settings.DisableTransferQueue = true;
_sftp.Settings.UploadBufferSize = 48 * 1024;

The log is below.

2019-09-24 19:49:02.780 INFO FileLogWriter(1)[13] Info: Assembly: Rebex.Common 2018 R2 for .NET 4.0-4.7
2019-09-24 19:49:02.784 INFO FileLogWriter(1)[13] Info: Platform: Windows 10.0.17134 32-bit; CLR: 4.0.30319.42000
2019-09-24 19:49:02.785 DEBUG FileLogWriter(1)[13] Info: Culture: en; Windows-1252
2019-09-24 19:49:02.815 DEBUG Sftp(1)[13] SSH: Allowed authentication methods for 'root': publickey, password.
2019-09-24 19:49:02.817 DEBUG Sftp(1)[13] SSH: Trying password authentication for 'root'.
2019-09-24 19:49:02.858 DEBUG Sftp(1)[13] SSH: Authentication successful.
2019-09-24 19:49:02.881 DEBUG Sftp(1)[13] SSH: Requesting subsystem 'sftp'.
2019-09-24 19:49:02.897 INFO Sftp(1)[13] Command: SSH_FXP_INIT (4)
2019-09-24 19:49:03.126 ERROR Sftp(1)[13] Info: Rebex.Net.SftpException: The server has closed the connection.
   at ctcy.mpez(Int32 arz)
   at ctcy.mpfb(hffs& asc)
   at ctcy.mpdu(SftpServerType aoe, ctch aof)
   at Rebex.Net.Sftp.ypkg(ctch qu)
   at Rebex.Net.Sftp.ypke(String qo, String qp, SshPrivateKey qq, ctch qr)
Applies to: Rebex SFTP
commented Sep 24 by Lukas Pokorny (103,170 points)
This looks like the server is disconnecting the client when it sends the initial SFTP protocol's SSH_FXP_INIT packet. If you add the following setting, does it have any effect?
  _sftp.Settings.DisableSftp4 = true;
commented Sep 24 by Prabhakar (500 points)
With DisableSftp4 = true, I get the below log

2019-09-24 20:15:32.223 Opening log file.
2019-09-24 20:15:32.225 INFO FileLogWriter(1)[12] Info: Assembly: Rebex.Common 2018 R2 for .NET 4.0-4.7
2019-09-24 20:15:32.227 INFO FileLogWriter(1)[12] Info: Platform: Windows 10.0.17134 32-bit; CLR: 4.0.30319.42000
2019-09-24 20:15:32.228 DEBUG FileLogWriter(1)[12] Info: Culture: en; Windows-1252
2019-09-24 20:15:33.387 VERBOSE Sftp(1)[12] SSH: Sending packet SSH_MSG_SERVICE_REQUEST (17 bytes).
 0000 |05-00-00-00-0C-73-73-68 2D-75-73-65-72-61-75-74| .....ssh-useraut
 0010 |68                                             | h
2019-09-24 20:15:33.398 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_SERVICE_ACCEPT (17 bytes).
 0000 |06-00-00-00-0C-73-73-68 2D-75-73-65-72-61-75-74| .....ssh-useraut
 0010 |68                                             | h
2019-09-24 20:15:33.399 VERBOSE Sftp(1)[12] SSH: Sending packet SSH_MSG_USERAUTH_REQUEST (35 bytes).
 0000 |32-00-00-00-04-72-6F-6F 74-00-00-00-0E-73-73-68| 2....root....ssh
 0010 |2D-63-6F-6E-6E-65-63-74 69-6F-6E-00-00-00-04-6E| -connection....n
 0020 |6F-6E-65                                       | one
2019-09-24 20:15:33.404 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_USERAUTH_FAILURE (24 bytes).
 0000 |33-00-00-00-12-70-75-62 6C-69-63-6B-65-79-2C-70| 3....publickey,p
 0010 |61-73-73-77-6F-72-64-00                        | assword.
2019-09-24 20:15:33.406 DEBUG Sftp(1)[12] SSH: Allowed authentication methods for 'root': publickey, password.
2019-09-24 20:15:33.408 DEBUG Sftp(1)[12] SSH: Trying password authentication for 'root'.
2019-09-24 20:15:33.409 VERBOSE Sftp(1)[12] SSH: Sending packet SSH_MSG_USERAUTH_REQUEST (48 bytes).
 0000 |32-00-00-00-04-72-6F-6F 74-00-00-00-0E-73-73-68| 2....root....ssh
 0010 |2D-63-6F-6E-6E-65-63-74 69-6F-6E-00-00-00-08-70| -connection....p
 0020 |61-73-73-77-6F-72-64-00 00-00-00-04-72-6F-6F-74| assword.....root
2019-09-24 20:15:33.523 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_USERAUTH_SUCCESS (1 bytes).
 0000 |34                                             | 4
2019-09-24 20:15:33.523 DEBUG Sftp(1)[12] SSH: Authentication successful.
2019-09-24 20:15:33.529 VERBOSE Sftp(1)[12] SSH: Sending packet SSH_MSG_CHANNEL_OPEN (24 bytes).
 0000 |5A-00-00-00-07-73-65-73 73-69-6F-6E-00-00-00-00| Z....session....
 0010 |00-02-00-00-00-01-F8-00                        | ........
2019-09-24 20:15:33.531 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_CHANNEL_OPEN_CONFIRMATION (17 bytes).
 0000 |5B-00-00-00-00-00-00-00 00-00-00-60-00-00-00-7F| [..........`....
 0010 |F7                                             | .
2019-09-24 20:15:33.538 DEBUG Sftp(1)[12] SSH: Requesting subsystem 'sftp'.
2019-09-24 20:15:33.540 VERBOSE Sftp(1)[12] SSH: Sending packet SSH_MSG_CHANNEL_REQUEST (27 bytes).
 0000 |62-00-00-00-00-00-00-00 09-73-75-62-73-79-73-74| b........subsyst
 0010 |65-6D-01-00-00-00-04-73 66-74-70               | em.....sftp
2019-09-24 20:15:33.542 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_CHANNEL_SUCCESS (5 bytes).
 0000 |63-00-00-00-00                                 | c....
2019-09-24 20:15:33.557 VERBOSE Sftp(1)[12] SSH: Sending packet SSH_MSG_CHANNEL_DATA (18 bytes).
 0000 |5E-00-00-00-00-00-00-00 09-00-00-00-05-01-00-00| ^...............
 0010 |00-03                                          | ..
2019-09-24 20:15:33.559 INFO Sftp(1)[12] Command: SSH_FXP_INIT (3)
2019-09-24 20:15:33.591 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_CHANNEL_EXTENDED_DATA (69 bytes).
 0000 |5F-00-00-00-00-00-00-00 01-00-00-00-38-73-68-3A| _...........8sh:
 0010 |20-2F-75-73-72-2F-6C-69 62-65-78-65-63-2F-73-66|  /usr/libexec/sf
 0020 |74-70-2D-73-65-72-76-65 72-3A-20-4E-6F-20-73-75| tp-server: No su
 0030 |63-68-20-66-69-6C-65-20 6F-72-20-64-69-72-65-63| ch file or direc
 0040 |74-6F-72-79-0A                                 | tory.
2019-09-24 20:15:33.634 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_CHANNEL_EOF (5 bytes).
 0000 |60-00-00-00-00                                 | `....
2019-09-24 20:15:33.634 VERBOSE Sftp(1)[14] SSH: Sending packet SSH_MSG_CHANNEL_EOF (5 bytes).
 0000 |60-00-00-00-00                                 | `....
2019-09-24 20:15:33.635 VERBOSE Sftp(1)[14] SSH: Sending packet SSH_MSG_CHANNEL_CLOSE (5 bytes).
 0000 |61-00-00-00-00                                 | a....
2019-09-24 20:15:33.635 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_CHANNEL_REQUEST (25 bytes).
 0000 |62-00-00-00-00-00-00-00 0B-65-78-69-74-2D-73-74| b........exit-st
 0010 |61-74-75-73-00-00-00-00 7F                     | atus.....
2019-09-24 20:15:33.636 VERBOSE Sftp(1)[14] SSH: Received packet SSH_MSG_CHANNEL_CLOSE (5 bytes).
 0000 |61-00-00-00-00                                 | a....
2019-09-24 20:15:33.731 ERROR Sftp(1)[12] Info: Rebex.Net.SftpException: The server has closed the connection.
   at ctcy.mpez(Int32 arz)
   at ctcy.mpfb(hffs& asc)
   at ctcy.mpdu(SftpServerType aoe, ctch aof)
   at Rebex.Net.Sftp.ypkg(ctch qu)
   at Rebex.Net.Sftp.ypke(String qo, String qp, SshPrivateKey qq, ctch qr)

1 Answer

0 votes
answered Sep 27 by Prabhakar (500 points)
It seems the server wasn't implemented properly. So we can close this ticket.
...