0 votes
by (130 points)

Hi,

I am uploading a large text file to an SFTP server so I break it up and upload with an offset.

The first batch is uploaded correctly but on the subsequent upload I get an error. This is my code to upload:

long offSet = 0;
if (sftp.FileExists(sPath))
{
  if (FirstUpload)
    sftp.DeleteFile(sPath);
  else
    offSet = sftp.GetFileLength(sPath);
}

using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(sData)))
{
  sftp.PutFile(stream, sPath, offSet, stream.Length);
}

And this is the log file:

2019-05-16 12:38:28.239 DEBUG Sftp(13)[6] SSH: Server is 'SSH-2.0-CrushFTPSSHD'.
2019-05-16 12:38:28.239 INFO Sftp(13)[6] SSH: Negotiation started.
2019-05-16 12:38:28.256 DEBUG Sftp(13)[6] SSH: Group exchange.
2019-05-16 12:38:28.545 DEBUG Sftp(13)[6] SSH: Negotiating key.
2019-05-16 12:38:28.932 DEBUG Sftp(13)[6] SSH: Validating signature.
2019-05-16 12:38:28.933 INFO Sftp(13)[6] SSH: Negotiation finished.
2019-05-16 12:38:28.933 INFO Sftp(13)[6] Info: Server: SSH-2.0-CrushFTPSSHD
2019-05-16 12:38:30.562 DEBUG Sftp(13)[6] SSH: Authentication successful.
2019-05-16 12:38:30.796 DEBUG Sftp(13)[6] SSH: Requesting subsystem 'sftp'.
2019-05-16 12:38:31.028 INFO Sftp(13)[6] Command: SSH_FXP_INIT (4)
2019-05-16 12:38:31.259 INFO Sftp(13)[6] Response: SSH_FXP_VERSION (4, 1 extension)
2019-05-16 12:38:31.259 INFO Sftp(13)[6] Info: Using SFTP v4 on a Unix-like platform.
2019-05-16 12:38:31.259 INFO Sftp(13)[6] Command: SSH_FXP_REALPATH (1, '.')
2019-05-16 12:38:31.493 INFO Sftp(13)[6] Response: SSH_FXP_NAME (1, 1 item)
2019-05-16 12:38:31.493 INFO Sftp(13)[6] Info: Current directory is '/'.
2019-05-16 12:38:31.493 INFO Sftp(13)[6] Command: SSH_FXP_STAT (2, '/Folder/Large File.csv')
2019-05-16 12:38:31.899 INFO Sftp(13)[6] Response: SSH_FXP_ATTRS (2)
2019-05-16 12:38:31.899 INFO Sftp(13)[6] Command: SSH_FXP_STAT (3, '/Folder/Large File.csv')
2019-05-16 12:38:32.133 INFO Sftp(13)[6] Response: SSH_FXP_ATTRS (3)
2019-05-16 12:38:32.135 INFO Sftp(13)[6] Command: SSH_FXP_OPEN (4, '/Folder/Large File.csv', 2)
2019-05-16 12:38:32.544 INFO Sftp(13)[6] Response: SSH_FXP_HANDLE (4, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A)
2019-05-16 12:38:32.545 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (5, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1010848, 28672 bytes)
2019-05-16 12:38:33.255 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (6, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1039520, 28672 bytes)
2019-05-16 12:38:33.492 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (7, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1068192, 28672 bytes)
2019-05-16 12:38:33.721 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (8, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1096864, 28672 bytes)
2019-05-16 12:38:33.729 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (9, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1125536, 28672 bytes)
2019-05-16 12:38:33.730 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (5, 0, 'The write completed successfully')
2019-05-16 12:38:33.956 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (10, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1154208, 28672 bytes)
2019-05-16 12:38:33.956 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (6, 0, 'The write completed successfully')
2019-05-16 12:38:33.966 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (11, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1182880, 28672 bytes)
2019-05-16 12:38:33.966 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (7, 0, 'The write completed successfully')
2019-05-16 12:38:34.193 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (12, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1211552, 28672 bytes)
2019-05-16 12:38:34.193 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (8, 0, 'The write completed successfully')
2019-05-16 12:38:34.203 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (13, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1240224, 28672 bytes)
2019-05-16 12:38:34.204 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (9, 0, 'The write completed successfully')
2019-05-16 12:38:34.424 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (14, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1268896, 28672 bytes)
2019-05-16 12:38:34.425 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (10, 0, 'The write completed successfully')
2019-05-16 12:38:34.436 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (15, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1297568, 28672 bytes)
2019-05-16 12:38:34.436 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (11, 0, 'The write completed successfully')
2019-05-16 12:38:34.658 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (16, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1326240, 28672 bytes)
2019-05-16 12:38:34.658 DEBUG Sftp(13)[6] Response: SSH_FXP_STATUS (12, 0, 'The write completed successfully')
2019-05-16 12:38:34.669 DEBUG Sftp(13)[6] Command: SSH_FXP_WRITE (17, 0x2F636F72652F4A4A4953475F4150444E415F6974785F61726D5F636F6E6170646E615F706163696669635F6465765F706572656E736F2F4558505F4163637447727052656C2E6373763A547844414A, 1354912, 28672 bytes)
2019-05-16 12:38:39.471 INFO Sftp(13)[6] Response: SSH_FXP_STATUS (13, 4, 'Connection reset')
2019-05-16 12:38:44.477 INFO Sftp(13)[6] Response: SSH_FXP_STATUS (14, 4, 'Connection reset')
2019-05-16 12:38:44.480 ERROR Sftp(13)[6] Info: Rebex.Net.SftpException: Failure; Connection reset.
   at Rebex.Net.YEB.EC(SDB A, Type B)
   at Rebex.Net.YEB.PB(UInt32 A, BEB B)
   at Rebex.Net.Sftp.VAB(VFB A, BEB B, String C, Stream D, Int64 E, Int64 H, WCB I)

Any idea what's going on here?

Thanks

Applies to: Rebex SFTP

1 Answer

+1 vote
by (144k points)

Hi,

It looks like the server suddenly starts rejecting further write requests with an error message of "Connection reset". This error comes from the SFTP server's file system, so it most likely indicates a server-side issue related to the file system. For example, for SFTP servers that store the actual file data in different locations from the server process, it might make sense to raise a "connection reset" error when an issue is encountered.

However, this is apparently a server-side issue. To determine what is going on, consult the server log, or ask the server vendor or server maintainer.

Otherwise, there is very little an SFTP client can do about it. But in some cases, it's possible to come up with a workaround by observing the server behavior. For example, if the server only starts failing when data is being uploaded too fast, limiting the uploading speed might help. In your scenario, try disabling the request queueing by setting Sftp's Settings.DisableTransferQueue = true and let us know whether this has any effect.

by (130 points)
Thanks Lukas for the prompt reply. Setting that flag still returns the same error so it looks like i'll have to work it through with the server vendor.

Thanks again.
by (144k points)
Yes. In the SFTP protocol, this error is an equivalent .NET's Stream.Write method failing with "Connection reset." IOException. Such errors make sense if the write has been to a remote file system, but they are not client-caused.
...