I have problem with uploading of several big files in one session into linux server.
for example:
I try to upload 17 files in loop.
3 - success, after that I waiting during 1 hour and then i get exception:
System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
I think that there is problem is in this part of code.
do
for example:
I try to upload 17 files in loop.
3 - success, after that I waiting during 1 hour and then i get exception:
System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
at Renci.SshNet.Sftp.SubsystemSession.WaitHandle(WaitHandle
waitHandle, TimeSpan operationTimeout)at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1
uploadCallback)I think that there is problem is in this part of code.
do
{
// Cancel upload
if (asyncResult != null && asyncResult.IsUploadCanceled)
break;
if (bytesRead > 0)
{
if (bytesRead < this.BufferSize)
{
// Replace buffer for last chunk of data
var data = new byte[bytesRead];
Buffer.BlockCopy(buffer, 0, data, 0, bytesRead);
buffer = data;
}
var writtenBytes = offset + (ulong)buffer.Length;
this._sftpSession.RequestWrite(handle, offset, buffer, null, (s) =>
{
if (s.StatusCode == StatusCodes.Ok)
{
expectedResponses--;
responseReceivedWaitHandle.Set();
// Call callback to report number of bytes written
if (uploadCallback != null)
{
// Execute callback on different thread
this.ExecuteThread(() => { uploadCallback(writtenBytes); });
}
}
});
expectedResponses++;
offset += (uint)bytesRead;
bytesRead = input.Read(buffer, 0, buffer.Length);
}
else if (expectedResponses > 0)
{
// Wait for expectedResponses to change
this._sftpSession.WaitHandle(responseReceivedWaitHandle, this.OperationTimeout);
}
} while (expectedResponses > 0 || bytesRead > 0);
this._sftpSession.RequestClose(handle);
}
I think the variable bytesRead became = 0 but expectedResponses can't be 0...